我试图在烧瓶中使用Bluprint来分割我的应用程序,但我得到了AssertionError,尽管没有相同名称的功能。我想如果函数名称不同,默认端点也会不同。我已经搜索过了,但到目前为止我仍然可以找到它。请帮忙;(
这是我的controllers.py
import flask
from flask import render_template, request, redirect, url_for, flash, make_response, g, session, jsonify
from apps import app, db
from apps.models import *
from apps.controllers2 import app2
#Set application.debug=true to enable tracebacks on Beanstalk log output.
#Make sure to remove this line before deploying to production.
app.debug=True
app.register_blueprint(app2)
@app.route('/', methods=['GET', 'POST'])
@app.route('/intro', methods=['GET', 'POST'])
def hmp_showIntro():
return render_template('intro.html')
if __name__ == '__main__':
app.run(host='0.0.0.0')
这是分离的控制器,controller2.py
from flask import render_template, request, redirect, url_for, flash, make_response, g, session, jsonify
from flask import Blueprint
from apps import app, db
app2 = Blueprint('app2', __name__)
@app2.route('/main')
def hmp_showMain():
return render_template('main.html')
这就是我所拥有的
mod_wsgi (pid=15429): Exception occurred processing WSGI script '/opt/python/current/app/apps/controllers.py'.
Traceback (most recent call last):
File "/opt/python/current/app/apps/controllers.py", line 17, in <module>
@app.route('/intro', methods=['GET', 'POST'])
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1013, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 984, in add_url_rule
'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: hmp_showIntro
答案 0 :(得分:0)
您的应用已经拥有以hmp_showIntro
名称查看的路线。搜索该功能的项目。或者你可以双重导入controllers.py。