《Flask Web开发》学习笔记之bug--(2)【AssertionError: View function mapping is overwriting an existing endpoi】

来源:互联网 发布:苹果6当前网络不可用 编辑:程序博客网 时间:2024/06/11 05:45
# hello.pyfrom datetime import datetimefrom flask import Flask, render_templatefrom flask_script import Managerfrom flask_bootstrap import Bootstrapfrom flask_moment import Momentapp = Flask(__name__)manager = Manager(app)bootstrap = Bootstrap(app)moment = Moment(app)@app.errorhandler(404)def page_not_found(e):return render_template('404.html'), 404@app.errorhandler(500)def internal_server_error(e):return render_template('500.html'), 500@app.route('/')def index():return render_template('index.html', current_time=datetime.utnow())@app.route('/')def index():return render_template('index.html')@app.route('/user/<name>')def user(name):return render_template('user.html', name=name)if __name__ == '__main__':manager.run()

$ python3 hello.py runserver --host 0.0.0.0Traceback (most recent call last):  File "hello.py", line 26, in <module>    @app.route('/')  File "/home/henry/.local/lib/python3.5/site-packages/flask/app.py", line 1080, in decorator    self.add_url_rule(rule, endpoint, f, **options)  File "/home/henry/.local/lib/python3.5/site-packages/flask/app.py", line 64, in wrapper_func    return f(self, *args, **kwargs)  File "/home/henry/.local/lib/python3.5/site-packages/flask/app.py", line 1051, in add_url_rule    'existing endpoint function: %s' % endpoint)AssertionError: View function mapping is overwriting an existing endpoint function: index

定位:

hello.py的@app.route('/')装饰器重写了index函数

解决办法:

删掉一个多余的index()函数。




阅读全文
0 0