hmorimitsu / flask-tutorial-plus

An adaptation of the Flask tutorial to use common Flask libraries: SQLAlchemy, WTForms, Login and Migrate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask Tutorial Plus

This repository contains a modified version of the official Flask tutorial. The code of the tutorial was adapted to take advantage of some common Flask libraries, including:

If you want to see an example of this same app using OAuth login with Google and Github, check my other repository at https://github.com/hmorimitsu/flask-tutorial-plus-oauth.

The application is still the same as in the original tutorial, and a significant part of the code remains unchanged. If you are interested in learning more about the code, I recommend you check the original tutorial, which explains everything nicely.

I wrote this code mostly to learn Flask myself, but I decided to make it public in case someone else wanted to see a relatively simple example of how to employ those Flask libraries in practice (as I did).

I did my best to follow good practices to write the code, but as I am new to Flask, I cannot guarantee everything is implemented in the best way. I consulted a few other sources to learn about the libraries, and they are listed in the Acknowledgements.

Requirements

  • Python 3
  • Flask
  • Flask SQLAlchemy
  • Flask WTForms
  • Flask Login
  • Flask Migrate
  • Flask Script

It is assumed you already have Python 3 with pip installed (if not, there are many tutorials about it). You should also be using some type environment, such as Virtualenv or Anaconda.

You can install all other required libraries with the command below:

pip install flask Flask-SQLAlchemy flask-login Flask-WTF Flask-Migrate Flask-Script

Alternatively, if you are using an environment, and you want to install the same versions of the libraries I used when writing this code, first complete the first two steps of the Usage and then run:

pip install -r requirements.txt

Usage

The instructions below show how to run this code using terminal in a Linux machine. If you are using another OS, you may have to adapt the instructions.

  1. Clone this repository:
git clone https://github.com/hmorimitsu/flask-tutorial-plus.git
  1. Enter the folder that was created by cloning the repository.
cd flask-tutorial-plus
  1. Use Flask Migrate to initialize the sqlite database. If you want to use another database (such as Postgres or MySQL), you will have the edit the DATABASE_URL in config.py) before starting this step.
bash manage_db.sh
  1. If there were any error during the migration, fix them before proceeding. If there are no errors, then you can start to serve the application by running:
python app.py
  1. Again, check for error messages and fix them. If no errors, then open a browser and enter the address informed in the terminal (tipically http://127.0.0.1:5000/). If everything goes well, you should see the initial page of the website.

Acknowledgements

A significant part of the code comes from the official Flask tutorial.

Besides, the following websites were used to implement parts related to other Flask libraries:

LICENSE

This code is licensed under the MIT License.

About

An adaptation of the Flask tutorial to use common Flask libraries: SQLAlchemy, WTForms, Login and Migrate.

License:MIT License


Languages

Language:Python 65.2%Language:HTML 23.6%Language:CSS 10.5%Language:Shell 0.7%