@app.route(‘/version‘)
def version():
return ‘Version: V0.1‘
@app.route(‘/user/<username>‘)
def get_username(username):
return ‘Username %s‘ % escape(username)
@app.route(‘/user/<int:user_id>‘)
def get_user_id(user_id):
return ‘Userid %d‘ % user_id
@app.route(‘/path/<path:subpath>‘)
def show_subpath(subpath):
return ‘Subpath %s‘ % escape(subpath)
@app.route(‘/projects/‘)
def projects():
return ‘The project page‘
@app.route(‘/about‘)
def about():
return ‘The about page‘
@app.route(‘/‘)
def index():
return ‘Hello World‘
@app.route(‘/version‘)
def version():
return ‘Version: V0.1‘
@app.route(‘/user/<username>‘)
def get_username(username):
return ‘Username %s‘ % escape(username)
with app.test_request_context():
print(url_for(‘index‘))
print(url_for(‘version‘))
print(url_for(‘get_username‘, username=‘John Doe‘))
@app.route(‘/key‘, methods=[‘GET‘, ‘POST‘])
def methods_test():
if request.method == ‘POST‘:
return ‘post key‘
else:
return ‘get key‘
原文:https://www.cnblogs.com/52why/p/13198772.html