flask route 方法不能使用 test

来源:互联网 发布:手机象棋打谱软件 编辑:程序博客网 时间:2024/06/06 03:43

flask route 方法名称不能使用 test,否则就会出现意外情况(导致 url 无法访问,右键启动类的时候现实的启动名称不对)

例如:有一个 request.py 文件,代码如下:

from flask import Flaskfrom flask import render_templateapp = Flask(__name__)@app.route('/')def index():    return 'Index page!'@app.route('/hello')def hello_world():    return 'Hello World!'@app.route('/user/<username>')def show_user_profile(username):    return 'User %s' % username@app.route('/post/<int:post_id>')def show_post(post_id):    return 'Post %d' % post_id@app.route('/about')def about():    return 'The about page'@app.route('/testt/')def test():    print "in test views"    return 'hello test'@app.route('/order')def order():    return 'hello order dd'@app.route('/template/<name>')def template(name=None):    return render_template('template.html', name=name)if __name__ == '__main__':    app.run()

1.使用 test 为 route 方法名称右键启动应用效果

这里写图片描述

2.注释掉 test 后的右键运行效果

这里写图片描述

因此:为了避免flask意外情况的发生,我们最好不要使用 test 这种名称作为方法名称。

原创粉丝点击