【发布时间】:2018-05-13 12:27:06
【问题描述】:
为什么在尝试使用渲染时出现此错误:
Traceback (most recent call last):
File "d:\Projects\jara.md\backend\flask\__init__.py", line 31, in <module>
@app.route('/update/<int:adv_id>', methods=['PUT'])
File "c:\Python27\lib\site-packages\flask\app.py", line 1080, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "c:\Python27\lib\site-packages\flask\app.py", line 64, in wrapper_func
return f(self, *args, **kwargs)
File "c:\Python27\lib\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: start
代码列表是:
app = Flask(__name__)
@app.route('/add', methods=['POST'])
def add():
return 'Add'
@app.route('/start/<int:adv_id>', methods=['PUT'])
def start(adv_id):
return 'start'
### Rendering ###
@app.route('/add', methods=['GET'])
def add():
return render_template('add.html')
if __name__ == "__main__":
app.run()
如您所见,我有两种方法 add() 用于 GET 和 POST 请求。
这条消息是什么意思?
self.add_url_rule(rule, endpoint, f, **options)
@app.route('/update/<int:adv_id>', methods=['PUT'])
def start(adv_id):
return 'update'
【问题讨论】:
-
你的代码中
@app.route('/update/<int:adv_id>', methods=['PUT'])在哪里? -
抱歉我错过了,添加到问题中
标签: python python-3.x flask