I am trying to learn to use django class based views .
I want to make a GET request and do some operations only if the user is super user , but when I call this API using curl , it always uses AnonymousUser
irrespective of what I send via the CURL command.
views.py
class handle_request(View):
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(handle_request, self).dispatch(request, *args, **kwargs)
def get(self, request):
print "GET request made"
print request.user # <-- this is always AnonymousUser
if not request.user.is_superuser:
return HttpResponse("User is not permitted this action",status=403)
else:
# Do something
urls.py
urlpatterns = [
url(r'^$', handle_request.as_view()),
url(r'^db', hello.views.db, name='db'),
url(r'^admin/', include(admin.site.urls)),
]
curl command
curl -u test:testpass http://0.0.0.0:5000
what is the correct way to pass username and password to class based django view ?