Posted on 2020-06-01T12:33:45Z by Kevin Foong
In this post we will go through how to create a fully functional login and registration form in Flask. Part 1 (this post) will go through the backend part - setting up Flask, Flask-SQLAlchemy and creating the database. In part 2 we will build the actual forms and templates and see this in action.
In this tutorial we will start from the beginning, assuming that you only have Python installed. This tutorial was created using Windows but should be similar for other operating systems.
1. Create a folder for your project. Then in this folder create a Python virtual environment.
python -m venv env
2. Activate your virtual environment.
3. Install the following packages.
Read more ...
Posted on 2020-05-10T12:41:32Z by Kevin Foong
Flask-Migrate is a great tool which allows Flask developers, using SQL Alchemy, to amend their database on the fly. This is important because it means you wont have to destroy your current table and any data within it, in order to make any changes.
Miguel Gringberg (who is also the author of Flask-Migrate and Flask guru) has a great blog post on how to use Flask-Migrate so I won't go through the basics here. I will however provide a few tips that I have learnt along the way.
Out of the box Flask-Migrate does not detect changes you make to the database field's size or type. For example it will not detect if you change a field from varchar (50) to varchar (100).
To solve this, when you instantiate Flask-Migrate, just make sure you add "compare_type = true" like so.
migrate = Migrate(compare_type=True)
Read more ...