2

I am trying to customize my register view for flask-security as specified in the documentation.

@security.register_context_processor
def security_register_processor():
    return dict(hello="world")

I don't know what return dict(hello="world") does. Am I supposed to be able to access this dict in the register_user view? Adding that line of code doesn't do anything to change the template at all. Is it supposed to show up in the template? How do I use this feature?

   <h1>Register</h1>
   <form action="{{ url_for_security('register') }}" method="POST" name="register_form">
    {{ register_user_form.hidden_tag() }}
    {{ register_user_form.email.label }} {{ register_user_form.email }}<br/>
    {{ register_user_form.password.label }} {{ register_user_form.password }}<br/>
    {{ register_user_form.password_confirm.label }} {{ register_user_form.password_confirm }}<br/>
    {{ register_user_form.submit }}
  </form>
  <p>{{ content }}</p>
4

1 回答 1

3

上下文处理器的行为类似于其他 Flask 上下文处理器。每个注册的函数都会返回一个新变量的字典以添加到模板上下文中。从那些相同的文档:

要向模板上下文添加更多值,您可以为所有视图或特定视图指定上下文处理器。

您的示例将 namehello和 value添加'world'到注册视图的上下文中。像任何其他模板变量一样使用它。

Hello, {{ hello }}!
于 2015-11-28T22:10:30.153 回答