Elena' s AI Blog

Joking Flask App

10 Dec 2023 (updated: 24 Aug 2026) / 22 minutes to read

Elena Daehnhardt

Midjourney, December 2023

If you click an affiliate link and subsequently make a purchase, I will earn a small commission at no additional cost (you pay nothing extra). This is important for promoting tools I like and supporting my blogging.

I thoroughly check the affiliated products' functionality and use them myself to ensure high-quality content for my readers. Thank you very much for motivating me to write.



TL;DR:
  • Build Flask apps: use @app.route() for URL endpoints, render_template() with Jinja2 templates, and serve CSS/images from the static/ folder. Always import 'request' before handling forms. Start Flask with 'flask run' or 'python app.py', and never run the built-in dev server in production.

Previous: Part 1 β€” Loop like a Pro with Python Iterators

Next: Part 3 β€” What is Docker?

Introduction: Build a Flask Web App in Python

Flask is a lightweight Python web framework for building web applications and APIs using @app.route() endpoints and Jinja2 templates. Flask is the closest thing Python has to a magic trick: a few lines of code and you have a working web server. In this post I will show you how to build a small web application that serves random jokes from a text file β€” perfect for learning the core ideas without drowning in boilerplate.

We will cover:

  • Installing Flask and setting up a virtual environment
  • Routing URLs to Python functions
  • Using Jinja2 templates to render HTML
  • Serving static files (CSS, images)
  • Handling form submissions
  • Wiring it all together into a working Joker App

The full source code is in the GitHub repository flask-random-joke.

What Is Python Flask?

Flask is a lightweight WSGI web framework for Python. It gives you routing, a templating engine, and a development server β€” nothing more, nothing less. This minimalism is exactly why it is a great first framework: you understand every line you write.

Flask is built on two libraries: Werkzeug (the WSGI toolkit that handles HTTP requests and responses) and Jinja2 (the templating engine). Both are worth knowing a little about even if Flask abstracts them away.

Building the Joker Flask App Step by Step

πŸ”’ Subscribe to keep reading.

ChatGPT prompts I used

πŸ”’ Subscribe to keep reading.

Conclusion: Flask Routing, Templates, and Static Files

πŸ”’ Subscribe to keep reading.

References

πŸ”’ Subscribe to keep reading.

You've hit a Deep Dive tutorial.

I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):

Already a subscriber? Use the magic link from your last newsletter, or reset your password.

New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in β€” use the same email afterwards.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.





Citation
Elena Daehnhardt. (2023) 'Joking Flask App', daehnhardt.com, 10 December 2023. Available at: https://daehnhardt.com/blog/2023/12/10/python-flask-app/
All Posts