Skip to content

rdarneal/flask-blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

flask-blog

Flask blog template integrated with Bootstrap 5.3 and custom css styling. Based on the tutorial by Miguel Grinberg

Table of Contents
  1. About The Project
  2. Getting Started
  3. Contact
  4. Acknowledgments

About The Project

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.


Flask-microblog

(back to top)

Built With

  • Python
  • Flask
  • Bootstrap
  • JQuery
  • Docker
  • ElasticSearch
  • MySQL

(back to top)

Getting Started

To get a local copy up and running follow these steps.

Prerequisites

To fully try this project on your machine you will need at minimum:

Installation

  1. Clone the repo
    git clone https://github.com/rdarneal/flask-blog.git
  2. Navigate to the new folder and open with VS Code
    cd flask-blog
    code .
  3. Create a new virtual environemnt folder venv
    python -m venv venv
  4. Activate the virtual environment
    venv/bin/activate
  5. Install Python packages
    pip install requirements.txt
  6. Set the .flaskenv file to match your top level blog.py filename
    FLASK_APP=blog.py
  7. 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'
  8. Run the app locally to test it:
    flask --debug run
  9. 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.

Deploying via Docker

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.

  1. 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

(back to top)

Contact

Robert Darneal - python-dev@robertdarneal.com

Project Link: https://github.com/rdarneal/flask-blog

(back to top)

Acknowledgments

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages