Building a Mini Blog with Python and Flask

Learn how to build a simple blog application using Python and Flask. Setup from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) # Simple in-memory storage posts = [] Routes @app.route('/') def index(): return render_template('index.html', posts=posts) @app.route('/post', methods=['GET', 'POST']) def create_post(): if request.method == 'POST': title = request.form['title'] content = request.form['content'] posts.append({'title': title, 'content': content}) return redirect(url_for('index')) return render_template('create_post.html') Templates <!-- index.html --> {% for post in posts %} <article> <h2>{{ post.title }}</h2> <p>{{ post.content }}</p> </article> {% endfor %} Running flask run Conclusion Build your first Flask blog application! 🚀

June 15, 2022 · 4276 views