from flask import Flask
app = Flask(__name__)
posts = {0: dict(title='Hello World', content='This is my first ever post !'}
@app.route('/')
def home():
return 'Hello World!'
@app.route('/post/(int:post_id)')
def post(post_id):
post = posts.get(post_id)
return f"Post {post['title']} , content:\n\n{post['content']}"
if __name__ == '__main__':
app.run(debug=True)
答案 0 :(得分:0)
使用@app.route('/post/<int:post_id>')
。请注意<>
。