Flask-Security 的上下文处理器的 return 值是如何使用的?
How is the return value of Flask-Security's context processor used?
我正尝试按照 documentation.
中指定的方式为 flask-security 自定义我的注册视图
@security.register_context_processor
def security_register_processor():
return dict(hello="world")
我不知道 return dict(hello="world")
是做什么的。我应该能够在 register_user 视图中访问这个字典吗?添加那行代码根本不会改变模板。它应该出现在模板中吗?如何使用此功能?
<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>
上下文处理器的行为与其他 Flask 上下文处理器一样。每个注册函数 returns 一个要添加到模板上下文的新变量字典。来自相同的文档:
To add more values to the template context, you can specify a context processor for all views or a specific view.
您的示例会将名称 hello
和值 'world'
添加到寄存器视图的上下文中。像使用任何其他模板变量一样使用它。
Hello, {{ hello }}!
我正尝试按照 documentation.
中指定的方式为 flask-security 自定义我的注册视图@security.register_context_processor
def security_register_processor():
return dict(hello="world")
我不知道 return dict(hello="world")
是做什么的。我应该能够在 register_user 视图中访问这个字典吗?添加那行代码根本不会改变模板。它应该出现在模板中吗?如何使用此功能?
<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>
上下文处理器的行为与其他 Flask 上下文处理器一样。每个注册函数 returns 一个要添加到模板上下文的新变量字典。来自相同的文档:
To add more values to the template context, you can specify a context processor for all views or a specific view.
您的示例会将名称 hello
和值 'world'
添加到寄存器视图的上下文中。像使用任何其他模板变量一样使用它。
Hello, {{ hello }}!