Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法解决我的烧瓶Blupprint断言错误_Python_Flask - Fatal编程技术网

Python 无法解决我的烧瓶Blupprint断言错误

Python 无法解决我的烧瓶Blupprint断言错误,python,flask,Python,Flask,我试图用flask中的Blupprint分割我的应用程序,但我得到了AssertionError,尽管没有同名的功能。我认为如果函数名不同,默认端点也会不同。我已经找过了,但还是走不远。请帮忙;( 这是我的控制器.py import flask from flask import render_template, request, redirect, url_for, flash, make_response, g, session, jsonify from apps import app,

我试图用flask中的Blupprint分割我的应用程序,但我得到了AssertionError,尽管没有同名的功能。我认为如果函数名不同,默认端点也会不同。我已经找过了,但还是走不远。请帮忙;(

这是我的控制器.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
mod_wsgi(pid=15429):处理wsgi脚本“/opt/python/current/app/apps/controllers.py”时发生异常。
回溯(最近一次呼叫最后一次):
文件“/opt/python/current/app/apps/controllers.py”,第17行,在
@app.route('/intro',methods=['GET','POST'])
文件“/opt/python/run/venv/lib/python2.7/site packages/flask/app.py”,第1013行,在decorator中
添加url规则(规则、端点、f、**选项)
文件“/opt/python/run/venv/lib/python2.7/site packages/flask/app.py”,第62行,在wrapper_func中
返回f(自,*args,**kwargs)
文件“/opt/python/run/venv/lib/python2.7/site packages/flask/app.py”,第984行,在add_url_规则中
'现有终结点函数:%s'%1!'
AssertionError:视图函数映射正在覆盖现有端点函数:hmp_showIntro

您的应用程序已经有了使用
hmp\u showIntro
名称查看的路径。在项目中搜索该函数。或者您可以双重导入controllers.py。

函数,如
url\u for
使用视图函数的名称解析url。这就是为什么不能有两个同名的视图函数
hmp\u showIntro
。它们是否在单独的蓝图中并不重要,因为蓝图只是在调用
app之前解除视图的注册。注册\u blueprint
,这与在主app对象上注册两次同名函数基本相同。你可以通过使用来避免这种情况。谢谢。我找不到双重进口发生在哪里,但问题解决了