0👍
✅
This shouldn’t be done on URL level, but view level. In the view that the URL redirects to, you can check if the user has the permissions he/she needs and then either return a site or return a 404 page or 403 forbidden page.
example:
from django.views.generic import TemplateView
from django.http import HttpResponseNotAllowed
class MyView(TemplateView):
template_name = 'sth.html'
def get(self, request, **kwargs):
if request.user.is_superuser():
return super().get(request, **kwargs)
return HttpResponseNotAllowed()
1👍
In your views.py:
from django.contrib.auth.decorators import user_passes_test
def my_check(user):
return user.username == 'A'
@user_passes_test(my_check)
def man_dash(request):
Source:stackexchange.com