posts = [ {"title": "Post 1", "content": "This is the content of Post 1.", "comments": ["Comment 1", "Comment 2"]}, {"title": "Post 2", "content": "This is the content of Post 2.", "comments": ["Comment 3"]}, ] @app.route('/') def index(): return render_template('index.html', posts=posts) @app.route('/post/') def view_post(post_id): if post_id < len(posts): post = posts[post_id] return render_template('post.html', post=post) else: return "Post not found" @app.route('/add_post', methods=['GET', 'POST']) def add_post(): if request.method == 'POST': title = request.form['title'] content = request.form['content'] posts.append({"title": title, "content": content, "comments": []}) return redirect(url_for('index')) return render_template('add_post.html') @app.route('/add_comment/', methods=['POST']) def add_comment(post_id): if post_id < len(posts): comment = request.form['comment'] posts[post_id]["comments"].append(comment) return redirect(url_for('view_post', post_id=post_id)) if __name__ == '__main__': app.run(debug=True)