2

我正在使用 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

请让我知道我在哪里写错了代码,我是否需要为社交登录制作一个单独的文件,或者我需要根据谷歌应用引擎进行一些设置。

4

1 回答 1

1

由于您得到的错误是:

    jinja2.exceptions.UndefinedError
    UndefinedError: 'form' is undefined

您可能不得不尝试使用表格。看看这是否有效

于 2013-09-30T19:30:28.033 回答