Flask blog template integrated with Bootstrap 5.3 and custom css styling. Based on the tutorial by Miguel Grinberg
Table of Contents
This project includes a flask blueprint application divided primarily into 3 parts with various features:
- Blog
- Post
- Explore
- View Users
- Follow/Unfollow Users
- Search Posts
- Profile management
- Authentication
- Registration
- Login
- Password Reset
- Error handling
The app is configured to use a mysql or sqllite database, and the repo is set-up for running via Docker.
The search posts capability is provided via Elasticsearch and is also primarily done through docker-container registration.
To get a local copy up and running follow these steps.
To fully try this project on your machine you will need at minimum:
- Clone the repo
git clone https://github.com/rdarneal/flask-blog.git
- Navigate to the new folder and open with VS Code
cd flask-blog code .
- Create a new virtual environemnt folder
venv
python -m venv venv
- Activate the virtual environment
venv/bin/activate
- Install Python packages
pip install requirements.txt
- Set the
.flaskenv
file to match your top levelblog.py
filenameFLASK_APP=blog.py
- Create a new
.env
file with vs code. IMPORTANT: Include.env
in your.gitignore
file! Don't share secrets.SECRET_KEY='yoursecretstring' MAIL_SERVER='your.smtp.mailserver.com' MAIL_PORT= 443 MAIL_USERNAME = 'mailusername' MAIL_PASSWORD = 'mailpassword' MAIL_USE_TLS = 1 ELASTICSEARCH_URL = 'http://localhost:9200'
- Run the app locally to test it:
flask --debug run
- Note that when running with this method, search funtionality will only work if you have an activate Elasticsearch docker image. See docker method below for the command to launch a elasticsearch container.
The application is also set-up to be fully deployable via docker containers.
To use the docker method you must first build the application
docker build -t blog:latest .
Three containers are required: MySQL, Elasticsearch, and the blog applciation.
- Each container can be launched sequentially
- Mysql
docker run --name mysql -d -e MYSQL_RANDOM_ROOT_PASSWORD=yes \ -e MYSQL_DATABASE=flask-blog -e MYSQL_USER=flask-blog \ -e MYSQL_PASSWORD=<database-password> \ mysql/mysql-server:latest
- Elasticsearch
docker run --name elasticsearch -d \ -p 9200:9200 -p 9300:9300 \ --rm -e "discovery.type=single-node" \ docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
- The app (-e sets the environment variables for the docker container)
docker run --name flask-blog -d -p 8000:5000 --rm -e SECRET_KEY=my-secret-key \ -e MAIL_SERVER=smtp.email.com -e MAIL_PORT=587 -e MAIL_USE_TLS=true \ -e MAIL_USERNAME=<your-email-username> -e MAIL_PASSWORD=<your-email-password> \ --link mysql:dbserver \ -e DATABASE_URL=mysql+pymysql://flask-blog:<database-password>@dbserver/flask-blog \ --link elasticsearch:elasticsearch \ -e ELASTICSEARCH_URL=http://elasticsearch:9200 \ flask-blog:latest
- Mysql
Robert Darneal - python-dev@robertdarneal.com
Project Link: https://github.com/rdarneal/flask-blog