开发者

Defining template variables in django-registration

开发者 https://www.devze.com 2023-03-07 06:22 出处:网络
I am trying pass a new variable into a template within django-registration. Here is the code I have --

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

# in the template:

&开发者_如何学Clt;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()


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()}
0

精彩评论

暂无评论...
验证码 换一张
取 消