Model–View–Controller
We try to move most of the decisions about what will be render
into the template.
For that we use some processors listed in settings.py
:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
...
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
...
],
},
},
]
It makes, for example, possible to know the user.
{{ user.username }}
Also, we can test if the user is a staff or superuser.
{% if user.is_staff or user.is_superuser %}
...
{% endif %}