Dan Rubio
Dan Rubio

Reputation: 4907

How is the return value of Flask-Security's context processor used?

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>

Upvotes: 3

Views: 1026

Answers (1)

davidism
davidism

Reputation: 127320

The context processor behaves like other Flask context processors. Each registered function returns a dict of new variables to add to the template context. From those same docs:

To add more values to the template context, you can specify a context processor for all views or a specific view.

Your example will add the name hello, with the value 'world' to the context of the register view. Use it like any other template variable.

Hello, {{ hello }}!

Upvotes: 3

Related Questions