当我的Flask程序编译时,尝试通过浏览器访问服务器会导致以下构建错误。
Traceback (most recent call last):
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/var/www/pulleffect/pulleffect/middleware/reverse_proxy_fix.py", line 34, in __call__
return self.app(environ, start_response)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/werkzeug/contrib/fixers.py", line 144, in __call__
return self.app(environ, start_response)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/var/www/pulleffect/pulleffect/lib/utilities.py", line 97, in decorated_function
return f(*args, **kwargs)
File "/var/www/pulleffect/pulleffect/__init__.py", line 86, in index
return render_template('index.html')
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template
context, ctx.app)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/templating.py", line 110, in _render
rv = template.render(context)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/var/www/pulleffect/pulleffect/templates/index.html", line 1, in top-level template code
{% extends "signin.html" %}
File "/var/www/pulleffect/pulleffect/templates/signin.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/var/www/pulleffect/pulleffect/templates/layout.html", line 35, in top-level
template code
var shiftsRoute = "{{ url_for('shifts.index') }}";
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/helpers.py", line 312, in url_for
return appctx.app.handle_url_build_error(error, endpoint, values)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/app.py", line 1641, in handle_url_build_error
reraise(exc_type, exc_value, tb)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/flask/helpers.py", line 305, in url_for
force_external=external)
File "/var/www/pulleffect/penv/lib/python2.7/site-packages/werkzeug/routing.py", line 1620, in build
raise BuildError(endpoint, values, method)
BuildError: ('shifts.index', {}, None)
我的理解是,通常这来自于通过其路由调用url而不是其方法。但是,在这种情况下,index是方法,而不是路由,仍然会引发错误。
这是程序中失败的特定行:
var shiftsRoute = "{{ url_for('shifts.index') }}";
这是方法索引。
@shifts.route('')
@require_signin
def index():
不幸的是,我很遗憾。我唯一的猜测是调用shift.index,要求索引包含在类班次中而不是简单地保存在shifting.py中。
答案 0 :(得分:0)
什么是班次?
你应该做的简单烧瓶:
@route('')
def index():
#do something
pass
然后:
url_for('index')