I have been learning flask for about 1 year now.
It has been fun, frustrating at times and I wish I would have finished the full documentation for it. But at least now I know how the different parts fit together, and all the “magic” that is inculde in Django is a developer’s choice when using flask.
But what a great micro web framework to use!
Flask is super easy to setup and works great if you are using RAD (Rapid-application development) or have a medium to small size app, it might work really good for bigs apps also, but then there is a lot of choices to consider for extensions and libraries to use.
- Pip install flask in your env
- Make a flask app
- Make a function with a route and then head to localhost:port/route
from flask import Flask, render_template
app = Flask(__name__)
return “hello world”
return render_template(“index.html”) index location app/templates/index.html
Good tips for bigger apps, use blueprints in flask.
But now I wanna try and learn Django for e-lo.
Short about flask
Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common framework related tools.
testit.tech with flask:
Note admin, with get all, get topic, new note, edit note and delete note:
Note get topic:
Note add, new note:
Pygal library testing:
pip freeze > requirements.txt
testit.tech was developed with:
- Flask, Python micro webframwork
- Jinja2 for templating, html
- Gunicorn webserver
- Nginx, reverse proxy
- Digital Ocean for hosting with linux
- A blog and a note-app was developed
Source code for testit.tech:
The text below is not part of tutorial, for internal reference only.
Install Nginx, remove default site, create your site, load gunicorn:
Good to know:
from app import app
(env) gunicorn –bind 0.0.0.0:port wsgi:app
Templates / static not loading after SFTP, stop / start gunicorn
sudo lsof -i:port
sudo lsof -i:8000
Not finding pid, pkill gunicorn
More on Gunicorn:
Workers increase, things got messed up
Hang in guniorn, showing old data from views (even though the code changed), cache issue, reboot server.
To reboot immediately you have to specify either of the cmds:
sudo shutdown -r 0
sudo shutdown -r now