Я делаю приложение в Google приложении с помощью Python Flask, и я новичок в Python Flask, каждый день изучая новые вещи. Я использую шаблон jinja2 с колбы он прекрасно работает на всех страницах, но он не признает {{ form.hidden_tag() }}
в моей странице регистрации пользователей и генерирует исключениеjinja2.exceptions.UndefinedError 'form' не определено в Python Flask
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
Пожалуйста, дайте мне знать, где я пишу код неправильно, мне нужно сделать файл seaperate для социального входа в систему или мне нужно сделать некоторые настройки в соответствии с движком Google.
Как выглядит ваш обработчик? Вы передаете «форму» в шаблон? – Greg
yes Я создал forms.py и определил форму в соответствии с моими моделями.py, а затем поместил форму в свой шаблон signup.html, но он выдает ошибку при первом первом объявлении, т. Е. {{form.hidden_tag() }} –
Greg Это обработчик, который я определил 'jinja_environment = jinja2.Environment (autoescape = True, loader = jinja2.FileSystemLoader (os.path.join ('.', 'Templates')))' –