# hello.py
from datetime import datetime
from flask import Flask, render_template
from flask_script import Manager
from flask_bootstrap import Bootstrap
from flask_moment import Moment
app = 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.0
Traceback (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()函数。