r/flask Sep 18 '21

Tutorials and Guides A Compilation of the Best Flask Tutorials for Beginners

344 Upvotes

I have made a list of the best Flask tutorials for beginners to learn web development. Beginners will benefit from it.


r/flask Feb 03 '23

Discussion Flask is Great!

122 Upvotes

I just wanted to say how much I love having a python backend with flask. I have a background in python from machine learning. However, I am new to backend development outside of PHP and found flask to be intuitive and overall very easy to implement. I've already been able to integrate external APIs like Chatgpt into web applications with flask, other APIs, and build my own python programs. Python has been such a useful tool for me I'm really excited to see what flask can accomplish!


r/flask 11h ago

Ask r/Flask Flask page works on desktop, but iOS Safari (iOS 26) only shows "Script error." and won't initialise

2 Upvotes

I have a page that works perfectly on desktop Chrome but won't initialise on iPhone (iOS 26.5.2). The HTML, CSS and my shared base.js all load with no failed network requests, but the page-specific script never runs, and the iOS console shows only the generic "Script error." with no line number.

Both JS files are same-origin (/static/js/...), which is what confuses me — "Script error." is usually a cross-origin thing.

Full code (public repo):

- Page script: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/static/js/alphabet.js

- Shared base: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/static/js/base.js

- Template + inline data: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/templates/alphabet.html

What I've already ruled out:

- No Safari-unsupported syntax (lookbehind, replaceAll, .at(), logical-assignment, private fields).

- No service worker; assets are cache-busted; cleared cache + tried Private mode.

- Desktop: every function defined, page runs with zero console errors.

- The page recently gained three study modes + a Pointer Events drag-and-drop rebuild and lazy new Audio() — the failure started after that.

Questions:

  1. On Windows (no Mac), what's the best way to reveal the real error behind iOS Safari's "Script error."? (I've added a window.onerror overlay.)

  2. What are the usual WebKit-only runtime throws that pass fine in Chrome/Blink? Anything about Pointer Events + setPointerCapture or new Audio() on iOS that throws at init?

Thanks!


r/flask 12h ago

Ask r/Flask Flask page works on desktop, but iOS Safari (iOS 26) only shows "Script error." and won't initialise

2 Upvotes

I have a page that works perfectly on desktop Chrome but won't initialise on iPhone (iOS 26.5.2). The HTML, CSS and my shared base.js all load with no failed network requests, but the page-specific script never runs, and the iOS console shows only the generic "Script error." with no line number.

Both JS files are same-origin (/static/js/...), which is what confuses me — "Script error." is usually a cross-origin thing.

Full code (public repo):

- Page script: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/static/js/alphabet.js

- Shared base: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/static/js/base.js

- Template + inline data: https://github.com/joshuablakemorekay/thaibridge-ai/blob/main/templates/alphabet.html

What I've already ruled out:

- No Safari-unsupported syntax (lookbehind, replaceAll, .at(), logical-assignment, private fields).

- No service worker; assets are cache-busted; cleared cache + tried Private mode.

- Desktop: every function defined, page runs with zero console errors.

- The page recently gained three study modes + a Pointer Events drag-and-drop rebuild and lazy new Audio() — the failure started after that.

Questions:

  1. On Windows (no Mac), what's the best way to reveal the real error behind iOS Safari's "Script error."? (I've added a window.onerror overlay.)

  2. What are the usual WebKit-only runtime throws that pass fine in Chrome/Blink? Anything about Pointer Events + setPointerCapture or new Audio() on iOS that throws at init?

Thanks!


r/flask 1d ago

Ask r/Flask Filter terminal output

0 Upvotes

Hi. I'm hoping this isn't a dumb question...

I'm looking for a way to filter the output Flask writes to stdout/stderr.

I want the output coming from logger: app.logger.info(message)

but I don't want the autogenerated output like:

x.x.x.x - - [21/Jul/2026 08:05:32] "GET / HTTP/1.1" 200 -

Reading on https://flask.palletsprojects.com/en/stable/logging/ I'm guessing it's some combination of settings I need to make in dictConfig() but I cant seem to figure it out.

Or I want to turn off Flask output altogether, and I'll use print() instead.

I'm writing a small REST application for work, meant to run in a container. Our container solution is very locked down, and the way to "write" logs from a container is to output to stdout and/or stderr inside the container and then some tool captures it and write to a log in the filesystem. I'm trying to find a way to keep that log as clean as possible


r/flask 2d ago

Ask r/Flask How do you handle Flask + Celery integration with extensions that aren’t fork-safe?

2 Upvotes

Hello! I am working on Flask application that uses celery and have a question concerning how celery spawns worker using prefork in default mode.

I needed to use PyMongo and started reading about its integration with flask and saw in the docs that 'PyMongo itself is not fork-safe'. Suddenly I realized, that the way I use Flask app inside celery may be wrong, though I am following the docs. Here is the code that creates celery app (taken from Flask docs):

from celery import Celery, Task

def celery_init_app(app: Flask) -> Celery:
    class FlaskTask(Task):
        def __call__(self, *args: object, **kwargs: object) -> object:
            with app.app_context():
                return self.run(*args, **kwargs)

    celery_app = Celery(app.name, task_cls=FlaskTask)
    celery_app.config_from_object(app.config["CELERY"])
    celery_app.set_default()
    app.extensions["celery"] = celery_app
    return celery_app

Celery start looks like this then:

  • first Flask application is created in the parent Celery worker process
  • then it is used to create celery app
  • and then this process is forked to create workers.

The problem is that PyMongo client is initialized as part of Flask App creation. But it shouldn't be forked as it is not safe. The same goes for other extensions that use live connections/sockets, as if they are created before fork, they may be inherited by child processes. Or extensions which spawn threads, that won't be copied to child process if I understand how fork works.

So my idea now is that I shouldn't initialize flask app during celery app creation, but I should initialize an app only inside a worker, using '@worker_process_init.connect' for example, and then use this worker specific app to create context for each task that needs it. This way all 'extensions' that are created inside flask app factory will be created inside the process that will be using them.

As my experience with multiprocessing is rather limited, I want to ask the community about this situation. How do you handle celery and flask integration? Should I create Flask application inside each Celery child worker process (e.g. via worker_process_init)? Or should I recreate only the extensions that are not fork-safe after the fork? My concern is not only about PyMongo, as Flask is used with a lot of other extensions and each of them may have its own 'fork' safety, so I am looking for some sort of general solution. Any help will be appreciated.


r/flask 2d ago

Ask r/Flask Is leetcode important?

1 Upvotes

I'm in university right now and leetcode is something that I'd have to go about learning.

I want to know if leetcode is somehow relevant to flask and if yes, in what parts,

because I kind of want to focus the way I study more towards this development side

Thanks!


r/flask 5d ago

Show and Tell A framework-agnostic "Storybook for htmx", with a Flask adapter

Post image
6 Upvotes

Previewing a single htmx partial in Flask is annoying, there's no isolated view for it.

You run the app, log in, click three pages deep just to see the one fragment you're editing. Storybook wants a JS build (kind of defeats htmx), and the polished component tools are all locked to one framework. So I made Swapbook.

  from swapbook import Registry, variant, click, expect_text


  reg = Registry(css_src="/static/app.css")
  reg.register("Signup", [
      variant("empty", lambda a: render_template("signup.html")),
      # a "play": scripted steps run against the preview, then asserted
      variant("invalid", lambda a: render_template("signup.html"),
              play=[click("#save"), expect_text("#err", "email is    required")]),
  ])


  app.register_blueprint(reg.blueprint)

(Not on PyPI yet, the adapter is a single file at adapters/flask/swapbook.py in the repo; drop it in or add it to your path for now. Packaging is on the list.)

The part I actually wanted: an inspector that shows the htmx requests a component fires, their params, status, which element got swapped, and the HTML that came back. Plus a mock mode that serves canned responses so you can click through a flow with no auth and no DB touched (safe/live modes too for real requests).

And play functions, like above: hit a button in the toolbar and it clicks/types/asserts against the preview, so a story can drive and verify a flow instead of just rendering a state. The thing that pushed me to build all this was a form partial that 422s and swaps in errors, painful to reach in the real app every time.

It's early and htmx is the path I've polished most. The protocol isn't Flask-specific so it also runs Django, Rails, Laravel, Express or a plain server, but the Flask adapter is new and I'd like eyes on it.

Doc: https://aejkatappaja.com/swapbook/

Repo: https://github.com/Aejkatappaja/swapbook

Tear it apart, or tell me what's missing vs how you preview components now.


r/flask 7d ago

Tutorials and Guides How do I learn flask?

7 Upvotes

I need to learn flask for an upcoming project, I'm starting Miguel's mega tut and it's great yet, but for a project that I would make, what else should I keep in mind? Especially when considering I need to learn terraform asw, please help.


r/flask 8d ago

Tutorials and Guides Flask Projects

0 Upvotes

I had learned Flask earlier, but due to other work, I had not written code for a while. Can anyone suggest some projects for me to learn back Flask?


r/flask 8d ago

Jobs [OFFER] Flask Backend Developer – task: Will fix bugs, build APIs, or set up MySQL/PostgreSQL databases (Quick turnaround, starting at $15)

0 Upvotes

I am a Computer Science Engineering student specializing in Python backend development and database management. If you have a Flask application that is broken, a database that won't connect, or you just need a fast, reliable REST API built, I can handle it for you today.

I don’t just write theoretical code—I build production-grade software. I designed and deployed my university's official Reading Room Seat Allotment System, which handles live, daily traffic for hundreds of students.


r/flask 10d ago

Show and Tell I needed one feature for my SaaS. Six hours later... I had launched another SaaS.

Thumbnail
0 Upvotes

r/flask 14d ago

Ask r/Flask Can somebody suggest a simple, working code showing how to add GitHub authentication to a flask app with JWT-extended?

8 Upvotes

I've already have a working app; Flask-Login is used for email authentication; Google Auth is added for Gmail authentication; both work perfectly.

Now, I'm trying to add a GitHub authentication and it seems to me I'm stuck forever. Whatever I do i hit the same problem: GitHub requires the redirection what causes losing cookies and as result; when the access token is expired, it never calls this code

u/jwt.expired_token_loader
def expired_token_callback(jwt_header, jwt_payload):
    request.data
    return default_expired_token_callback(jwt_header, jwt_payload)

My JS interceptor can't correctly handle the issue and doesn't call the corresponding code to refresh it.

Tried to use AI but the same result - just hit a wall. Google stupidly can't find any examples because it treats my query wrong (it thinks I'm looking for a code on GitHub completely ignoring that I need GitHub authentication example).

Please help!

UPDATE

Finally, found the issue. It turned out that I returned wrong url. Instead of creating a response with all the cookies, I returned the bare redirect - this is why the expored_token_loader was never hit, now I return this

def login_create_tokens_redirect(user_id, redirect_url):
    access_token = create_access_token(identity = user_id)
    refresh_token = create_refresh_token(identity = user_id)


    login_response = redirect(redirect_url)
    
    set_access_cookies(login_response, access_token)
    set_refresh_cookies(login_response, refresh_token)
    return login_response

r/flask 15d ago

Show and Tell Wordle Style Medical Game

3 Upvotes

Wordle style medical game! Built a daily Wordle-style medical terminology guessing game — 4 escalating clues, guess the term before you run out of tries. Flask + PostgreSQL, deployed on Render's free tier (so give it ~30s on first load, it spins down when idle).

Would love feedback & thanks a lot for supporting!!!

I think reddit has smtg against Render. It wont let me post it. Here's a QR:


r/flask 19d ago

Show and Tell 3rd year CSE student here — deployed a Flask+MySQL app with Jenkins CI/CD on AWS EC2, sharing what broke

Post image
9 Upvotes

Wanted to actually deploy something end-to-end instead of just doing tutorials, so I built a two-tier Flask/MySQL app and set up a full CI/CD pipeline: Docker Compose + Jenkins on an EC2 instance.

The tutorials never mention the annoying stuff, so here's what actually went wrong for me:

●MySQL container wasn't ready when Flask tried to connect → had to deal with startup race conditions

●Jenkins kept failing builds because of /tmp RAM-disk conflicts on the instance

●Had to migrate to PyMySQL partway through

●Signing key rotation instead of hardcoding secrets (learned this the hard way)

Attaching the architecture diagram below. Repo's here if anyone wants to poke around or roast my Jenkinsfile: github.com/Amirtha655/two-tier-flask-cicd

Still learning DevOps, so any feedback — good, bad, "why would you do it that way" — is welcome.


r/flask 23d ago

Ask r/Flask Looking for a free Flask hosting alternative to PythonAnywhere (with open outbound HTTP requests for AI/RAG)

12 Upvotes

I’m a 15yo guy and I’m learning Flask. I’m coding an iOS app in Swift that uses a Flask backend as an API. In this app, I’m doing some experiments with AI, RAG, and embeddings.

I’ve deployed my backend on PythonAnywhere, but as a young developer, I have to use the free plan. Now I’m in trouble because PythonAnywhere's free tier has a strict outbound internet whitelist that prevents me from calling external APIs (like Hugging Face for my embeddings), and it doesn't allow me to easily run background tasks or heavy scripts due to memory/storage limits. I also don't have the money right now to upgrade or use paid hosting.

So, I’m searching for a free hosting alternative to deploy my Flask server where I can freely call external APIs and that stays up for a long time. The first time i chose python anywhere because it stays up for 15 days and i wanted something similar. Any recommendations for my use? I also prefer not to insert a credit card on the website during registration. Thanks for helping!


r/flask 26d ago

Discussion Trying to get into flask but I'm having troubles with it.

6 Upvotes

Done a fair bit of Django, now poking at Flask for small stuff (with AI help ofc). Recently built a little HealthReporter UI with Flask as the API, it uses AI to read my app's stats from Prometheus, and my GitHub PRs, and it evaluates if something recently merged is causing issues with any of the services. My actual prod app is Next.js + Django, but this was small enough that I figured I'd finally give Flask a shot.

Maybe I went about it wrong, but I ended up having to build out basically everything myself. Didn't feel like a "framework" the way Django does, way more lightweight, which is nice, but also a lot more wiring on my end.

Is that normal, or am I just going about it wrong?


r/flask 26d ago

Ask r/Flask Based on your OWN personal experience, what would you consider to be the prerequisites to learning Flask?

2 Upvotes

Beginner here. What would you advice someone to learn apart from just saying "learn Python"

I'm genuinely curious


r/flask Jun 21 '26

Ask r/Flask Get public IPv6 host Flask server address

7 Upvotes

When I run Flask:

app.run(host="::", port=5000) # :: binds to all IPv6 interfaces. FOR DEV/TEST only

I get this:

 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (::)
 * Running on http://[::1]:5000
 * Running on http://[3499:7010:bb23:4321:f1ce:c68e:698d:1234]:5000

Is there a Flask means to retrieve the public IPv6 listed on the last line, 3499:7010:bb23:4321:f1ce:c68e:698d:1234?

I tried:

os.getenv("FLASK_RUN_HOST", "127.0.0.1")

and I just get the local net IPv4 address, 192.168.1.160.

 I've also tried:

urlparse(request.base_url) 

but it just returns "localhost".

I'm looking for the IPV6 reported on the above stated last line. (MyIPV6 changes dynamically.)


r/flask Jun 21 '26

Discussion I'm having trouble understanding what the syntax does as a beginner

6 Upvotes

I started learning Flask yesterday. So far think I've managed to grasp the basic layout of a Flask program but I'm having trouble understanding exactly what the syntax does.

What does app.route mean? What do you mean app.route is an instance of an application which you have to create after importing Flask?

Like I'm new to backend so these concepts don't make sense to me.

I would like an explanation on the purpose of:

creating an app and an instance of it

What request.args is?

I made my first program for practice after following a YouTube tutorial if that helps:

from flask import Flask, request

app = Flask(__name__)

@app.route("/")

def hello_world():

return "<p>Hello, World!</p>"

@app.route('/hello')

def hello():

return 'hello idiot'

@app.route('/eat/<food>')

def eat(food):

return f'I love eating {food} everyday!'

@app.route('/multiply/<int:num1>/<int:num2>')

def multiply(num1, num2):

return f'{num1} times {num2} = {num1*num2}'

# @app.route('/handleURLparams')

# def handleParams():

# return str(request.args)

# THIS IS HOW TO CALL ImmutableMultiDict([])

@app.route('/handleURLparams')

def handleParams():

if 'greeting' in request.args.keys() and request.args.keys():

greeting = request.args.get('greeting')

name = request.args['name']

return f'{greeting}, {name}'

else:

return 'Some parameters are missing'

if __name__ == '__main__':

app.run(debug=True, port=5555, host='0.0.0.0')


r/flask Jun 19 '26

Tutorials and Guides Regarding learning.

0 Upvotes

I want to learn flask for ml and some stuff. Not that deep however I want to learn such that it covers ml work. Can someone suggest some playlist under 4 -5 hrs that I can watch and that explains from basic. Again I don't wanna gk that deep but yes I can see from top top.


r/flask Jun 14 '26

Ask r/Flask I have develop many apps by using Python tkinter,django,flask and fasapi but i could not monetize it

Thumbnail
0 Upvotes

r/flask Jun 13 '26

Ask r/Flask How to practice Flask Development?

5 Upvotes

Currently I am going through Flask Development Second edition by Miguel Grinberg,

I have finished 8 chapters and am currently trying to learn how to go about building those kind of web applications,

The thing that I currently have an issue with is going about implementing them, I try doing projects that actively test my knowledge, and sometimes I figure it is a bit difficult for me to do them, for example, when I try implementing things from chapter 5 databases on a project as a practice, it becomes a bit difficult to go about implementing it.

But now that I am in chapter 9, it's hard to do both, so any suggestions on how to go about doing those practice then and there itself?


r/flask Jun 11 '26

Ask r/Flask Sharing resources between function views

2 Upvotes

Hello I am currently working on a post app with Flask and SQLAlchemy.

I have several routes/view functions like:

post/show_posts

post/history

post/edit

And basically I am fetching almost the same data from the same DB for different purposes (depending of the view function).

So I was wondering if there is a DRY good practice to keep models data as share resources between views instead of frequently fetch data by using the same SQLAlchemy core tools on each view function.


r/flask Jun 10 '26

Tutorials and Guides Giving back to the community - The Complete Backend Development Course

21 Upvotes

Hey everyone, I decided to make my course free in order to help people.
This course is my backend development course which is about SQL, Python, Flask, APIs, Docker, Kubernetes, Linux, Git & More

The link is: https://www.youtube.com/watch?v=CBIu6hcyStg

If you can like and subscribe (and maybe add a comment) I would appreciate it a lot, Thanks.