Skip to content

A blogging website created in Flask Python using a Codemy playlist

Notifications You must be signed in to change notification settings

faryar251/flasker

Repository files navigation

Flasker

  1. Introduction
    1.1 Technologies Used
    1.2 Screenshots
  2. Installation Instructions
    2.1. Download the code
    2.2. Update create_db.py
    2.3. Create a .env file
    2.4. Import model from the terminal
    2.5. Hiding the necessary files using .gitignore
  3. Running the Webapp in Local Machine
  4. Future Plans

This is a blogging website created in Flask Python using a Codemy playlist. I have made many changes and modified the design of the website as to my liking. Additional features will also be addressed.

1.1. Technologies Used

Python Flask Jinja MySQL SQLite HTML5 Bootstrap Postgres Gunicorn Heroku

1.2. Screenshots

Here are some screenshots of the website in the Development Environment:

login

profile

home

addpost

search


Note: I have used Git Bash for the project and provided the code for the same.

2.1. Download the code

Note: hello.py from the playlist has been changed to app.py.

  • Fork and clone this repository to your local machine.
  • Create a virtual environment (link)
  • Activate the virtual environment.
  • Install all the necessary dependencies and modules inside the virtual environment:
pip install -r requirements.txt

2.2. Update create_db.py

This is for MySQL only. Before taking data from the users, it is necessary to make sure the database exists, where all the required information for the website is stored in your local device.

Note: The database is created with the name our_users. You will see the db name in the SQLALCHEMY_DATABASE_URI as well.

Steps to follow:

  • Uncomment the entire create_db.py file.
  • Execute or run the .py file just once, to create the database in your local device.
  • Comment it again as the database with the name our_users exists now.

2.3. Create a .env file

Paste the following code and modify the code according to the comments.

# secret key 
# replace the string with your secret key.
SECRET_KEY = "my super secret key that no one is supposed to know!!"


# database 
# uncomment whichever database you are using.
# Replace {username} and {password} with your MySQL username and password.

# sqllite
# SQLALCHEMY_DATABASE_URI = 'sqlite:///users.db'

# mysql
# SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://{username}:{password}@localhost:3306/our_users'

2.4. Import model from the terminal (link to the playlist video)

Open the python interative shell

  • If using linux terminal:
$ winpty python
  • Create db
>>> from app import db
>>> db.create_all()

2.5. Hiding the necessary files using .gitignore Make sure to create a .gitignore file to hide neccessary files like .env and .gitignore. For this, just create a file with the name .gitignore in your project folder and copy paste the below code:

.gitignore
{virt_env_name}/
.env

  • Open your project folder in Git Bash.
  • Activate your virtual environment.
$ source {virt_env_name}/bin/activate
  • Open app.py file and make the following modifications to switch to the development environment.
# configuring flask app
app.config.from_object('config.Config')
# -- development env
app.config.from_object('config.DevConfig')
# -- production env
# app.config.from_object('config.ProdConfig')

Note: To switch back to Production Environment, just comment the development env code and uncomment the production env code.

  • Set Flask app and run.
$ export FLASK_APP=app.py
$ export FLASK_DEBUG=1
$ flask run

Here, setting FLASK_DEBUG=1 is only for the development environment.


  • Create a comment section under individual posts.
  • Add likes and comments in each post and display it in Author's list of work in their profile.
  • Add a CKE Editor for About Author section.

About

A blogging website created in Flask Python using a Codemy playlist

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages