user758733
user758733

Reputation: 13

Defining template variables in django-registration

I am trying pass a new variable into a template within django-registration. Here is the code I have --

# in the template:

<table>
{% for user in user_list %}
<tr>
    <td>{{ user.username }}</td>

</tr>
{% endfor %}
<table>

Where would I put the following user_list definition?

from django.contrib.auth.models import User
'user_list':User.objects.all()

Upvotes: 0

Views: 291

Answers (1)

MBarsi
MBarsi

Reputation: 2457

you can append a new method to TEMPLATE_CONTEXT_PROCESSORS in settings.py, e.g.

 #setting.py
    TEMPLATE_CONTEXT_PROCESSORS = (
    'other_contexts',
    'yourproject.yourcontextfile.yourcontextmethod',
      )

and then in your yourcontextfile.py write yourcontextmethod like this:

from django.contrib.auth.models import User

    def yourcontextmethod(request):
        return {'user_list':User.objects.all()}

Upvotes: 2

Related Questions