[Django]-Django: how to make part of the template visible only for admin

2👍

{% if user.is_staff %}
    code code code...
{% endif %}

And in views.py add this:

@login_required
def pamokosLOG(request):
    return render(request, 'NEpamokosLOG.html', 
                              {'full_name': request.user.username, 'pamokos': Pamoka.objects.all() })

2👍

Current user can be accessible by request.user if your add 'django.core.context_processors.request' to your TEMPLATE_CONTEXT_PROCESSORS

And if you want to check superuser status, use is_superuser and is_staff:

{% if request.user.is_staff and request.user.is_superuser %}
    code
{% endif %}

Do not forget to assign those attributes to your users.

👤Zulu

Leave a comment