我正在使用Python Flask在Google应用引擎上制作应用程序,我是Python Flask的新手,每天都在学习新东西。我正在使用带烧瓶的jinja2模板,它可以在所有页面上正常工作,但它无法识别
{{ form.hidden_tag() }}
在我的用户注册页面中并抛出异常
jinja2.exceptions.UndefinedError
这是我的Signup.html代码
`<!-- This is my page -->
{% extends "base.html" %}
{% block title %} Sign up | Eventus {% endblock %}
{% block style_block %}
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='bootstrap/css/social-buttons.css') }}" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="container theme-showcase">
<div class="row">
<h3><center>Sign Up Uscore</center></h3><br><br>
<div class="col-sm-6">
<form id="signup" class="navbar-form form-inline" action="{{ url_for('signup_action') }}" method="post" >
<fieldset>
{{ form.hidden_tag() }}
<div class="control-group">
<div class="control-label">{{ form.example_name.label }}</div>
<div class="controls">
{{ form.example_name|safe }}
{% if form.example_name.errors %}
<ul class="errors">
{% for error in form.example_name.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div class="control-group">
<div class="control-label">{{ form.example_description.label }}</div>
<div class="controls">
{{ form.example_description|safe }}
{% if form.example_description.errors %}
<ul class="errors">
{% for error in form.example_description.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="btn btn-primary" type="submit" value="Add Example"/>
<button class="btn" data-dismiss="modal">Cancel</button>
</div>
</div>
</fieldset>
<!-- <input type="text" name="username" value="{{username}}" placeholder="your username" class="form-control"></input><br><br>
<input type="text" name="email" value="{{email}}" placeholder="your email" class="form-control"></input><br><br>
<input type="password" name="password" value="{{password}}" placeholder="your password" class="form-control"></input><br><br>
<input type="password" name="confpassword" value="" placeholder="retype password" class="form-control" /><br><br><br>
<input type="checkbox" name="remember" value="" class="form-control" style="width: 15px; height: 12px;"/> Remember me
<a href="" class="pull-right">forgot password</a><br><br><br>
<input type="submit" name="signup_submit" value"Sign Up" class="btn btn-success" />
Already a Member<a href="" > Sign in </a> -->
</form>
</div>
<div class="col-sm-1">
</div>
<div class="col-sm-5">
<a class="btn btn-block btn-lg btn-google-plus" href="/signin/google/">
<i class="icon icon-google-plus"></i>
Sign in with Google
</a>
<a class="btn btn-block btn-lg btn-google-plus" href="/signin/googleoauth/">
<i class="icon icon-google-plus"></i>
Sign in with Google plus
</a>
<a class="btn btn-block btn-lg btn-facebook" href="/signin/facebook/">
<i class="icon icon-facebook"></i>
Sign in with Facebook
</a>
<a class="btn btn-block btn-lg btn-twitter" href="/signin/twitter/">
<i class="icon icon-twitter"></i>
Sign in with Twitter
</a>
</div>
</div>
</div>
{% endblock %}
以下是我在网页上出现的错误
jinja2.exceptions.UndefinedError
UndefinedError: 'form' is undefined
Traceback (most recent call last)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask_debugtoolbar/__init__.py", line 101, in dispatch_request
return view_func(**req.view_args)
File "/usr/lib/python2.7/cProfile.py", line 149, in runcall
return func(*args, **kw)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/views.py", line 149, in dispatch_request
return meth(*args, **kwargs)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/application/views.py", line 154, in get
return flask.render_template('signup.html')
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/templating.py", line 128, in render_template
context, ctx.app)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/lib/flask/templating.py", line 110, in _render
rv = template.render(context)
File "/home/chitrank/Documents/Google_App_Engine/flask_vir/google_appengine/lib/jinja2-2.6/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "/home/chitrank/Documents/Google_App_Engine/GoogleCloudPlatform/uscore-production/uscore/src/application/templates/signup.html", line 1, in top-level template code
{% extends "base.html" %}
UndefinedError: 'form' is undefined
请告诉我编写错误代码的位置,是否需要为社交登录制作海盗文件,或者我需要根据Google应用引擎进行一些设置。
答案 0 :(得分:1)
由于你得到的错误是:
jinja2.exceptions.UndefinedError
UndefinedError: 'form' is undefined
您可能需要尝试使用表单。看看是否有效