http://127.0.0.1:5000/post/0无法正常工作

时间:2018-06-28 17:29:44

标签: python flask

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)

1 个答案:

答案 0 :(得分:0)

使用@app.route('/post/<int:post_id>')。请注意<>