Django-registration에서 템플릿 변수 정의
-
15-11-2019 - |
문제
나는 Django 등록 내의 템플릿으로 새로운 변수를 전달하고 있습니다.여기 코드가있는 코드입니다 -
# in the template:
<table>
{% for user in user_list %}
<tr>
<td>{{ user.username }}</td>
</tr>
{% endfor %}
<table>
.
다음 user_list
정의를 어디에서 넣을 것입니까?
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()}
제휴하지 않습니다 StackOverflow