DEV Community

Cover image for Flask Tutorial - The Interactive way, Ask Me Anything for three hours
Sm0ke
Sm0ke

Posted on • Edited on

Flask Tutorial - The Interactive way, Ask Me Anything for three hours

Hello Coders,

My (nick)name is Sm0ke and I'm using Flask for more than 5 years to code almost anything: simple one-page projects, API's and eCommerce-based platforms. The deployments were made starting with Apache, Nginx, Gunicorn, and uWSGI .. etc. Regarding this Flask Tutorial, the content will be provided based on your questions, starting with just a few links.


Thank you! Content provided by AppSeed - App Generator.


I'll be around here for 3hours - feel free to ask me anything. During this timeframe I'll do my best to provide quality answers based on my practical knowledge - Some Flask-related links:


Suggested Topics:

  • Deployment on CentOS, Ubuntu using Apache/Nginx
  • Start app using Gunicorn, uWSGI
  • What is WSGI
  • How to structure a project
  • ORM - how to use it and manage DB information with ease
  • Migrations - using Flask Migration
  • Flask Admin - using roles in a Flask application
  • Protecting routes in Flask
  • Session-based authentication via Flask-Login
  • Using the Flask CLI
  • Create custom (CLI) commands using Click
  • Create tables dynamically - at first request

Top comments (20)

Collapse
 
arturo2r profile image
ArturoDRR

Hello what is the simplest and cheapest way to deploy a flask site?
I am beginner and recently I had an opportunity to make a landing page for an architecture agency, and I saw that flask is very easy to use, but I am seeing that some shared hostings doesn't support python. What you suggest me to do, or do I have to change stack. Thank you.

Collapse
 
sm0ke profile image
Sm0ke

Heroku has a free tier and is super easy to set up.
Another option is to buy a 5$ Droplet on DigitalOcean and use it for many projects.
Also, using a raw droplet, and make your own configuration in Apache/Nginx you will learn a lot.

Collapse
 
crearesite profile image
WebsiteMarket

Hello Sm0ke and Thanks for your time!
Can I use Flask embedded server for a production deploy?
I'm a beginner and configuring Apache/Nginx is not an easy job for me.

Collapse
 
sm0ke profile image
Sm0ke

Hello,
Flask provides the embedded server mostly for development purposes. As mentioned on the official docs regarding the deployment, "Flask’s built-in server is not suitable for production".

Besides this warning, I see two major problems:

  • you cannot enforce SSL and the connections will be served via HTTP
  • The Flask core is not build to handle concurrency

Even is not a simple task to configure a server, once you learn to do it, your application will be faster and secure.

Collapse
 
abuakram profile image
abuakram

Hi... thanks for your effort...
I was thinking of creating a folder in my flask project which is synchronized with my database... So that to speed up the speed...
Is this possible???

Collapse
 
sm0ke profile image
Sm0ke

Hello,
Your pattern is quite original. Can you elaborate, please?
If you want to speed up things, not only in Flask, you have at least two options:

  • Tune-up the database - define indexes on tables, using stored procedures, views
  • Use Redis to cache in memory critical information

If you have the time, please access this guide related to Flask:

How to increase Flask performance

Collapse
 
abuakram profile image
abuakram

Your link is so rich of important information... I couldn't stop reading... Are you by any chance Smirnov???

Concerning speed, since querying a database takes time... I thought of creating a folder that does a query to the db only after each update for synchronization (mirror of db) ... So it should be acting similar to flatpages.

Thread Thread
 
sm0ke profile image
Sm0ke

Smirnov??? .. who's this guy?

Between flatpages and DB pretty sure DB is faster and easier to locate the information.
On top of this, Redis is usually a solution to by-pass the DB queries.

Cheers!

Thread Thread
 
abuakram profile image
abuakram
Thread Thread
 
sm0ke profile image
Sm0ke

Nope :)

Collapse
 
abuakram profile image
abuakram

Hi, a second question please...
Concerning security, does one have to depend on extensions to gain full security, or is Flask enough... I am asking this question because a developer can stop maintaining his extension and apps relying on it gets buggy.

Collapse
 
sm0ke profile image
Sm0ke • Edited

Secure a web app is not an easy job but Flask helps a lot regarding this sensitive topic.
When your application uses a public module it might be a good idea to check a few relevant metrics:

  • The number of opened issues
  • Date of the latest commit

Also, you can open a discussion on StackOverflow/Reddit and get answers from other coders with a similar concern.

Usually, I'm checking the new modules by following this short checklist.

P.S. If you are using Github, feel free to use Flask Tutorial to get answers related to Flask.

Collapse
 
uithemes profile image
ui-themes

Cool idea. What are blueprints? When is recommended to use BP.
Ty!

Collapse
 
sm0ke profile image
Sm0ke • Edited

Blueprints are basically modules, similar to apps in Django.
Once a project is getting bigger, the files tend to become huge and not so easy to handle.
Using Blueprints, we can split the features using a modular structure. The official documentation is nicely written. Take a look and let me know if your thoughts.

Flask Blueprints - docs

Collapse
 
jonyk56 profile image
Jonyk56

is flask able to have endpoints closed/opened on command?

Collapse
 
sm0ke profile image
Sm0ke • Edited

Can you elaborate, please?
if your Q address something like a dynamic routing based on the input, I think you can manage this in a controller and bypass the classic Flask routing:

@app.route('/whatever.html', methods=['GET', 'POST'])
def whatever():
    ... Routing hacks HERE
Enter fullscreen mode Exit fullscreen mode
Collapse
 
climentea profile image
Alin Climente

Do you have/Can you recommend a repo for a docker(-compose) setup dev+prod ?

Collapse
 
sm0ke profile image
Sm0ke

Hello,

I've built some starters in Flask, already Dockerized. For sure the repos are not the best on the market but can be used to have a good start:

Both are tested and released under MIT License.

Collapse
 
keshavadk profile image
keshavadk

Thank you very much for this article and explanation.

Collapse
 
sm0ke profile image
Sm0ke

Yw & Thanks for stopping by.