django |基于类的视图|用户密码无法使用curl工作

时间:2016-05-28 19:58:09

标签: django curl django-class-based-views

我正在尝试学习使用基于django类的视图。 我想发出一个GET请求并仅在用户是超级用户时才进行一些操作,但是当我使用curl调用此API时,无论我通过CURL命令发送什么,它总是使用.introduction { background-image: url('../images/karma-background.jpg'); height: 100px; width: 100px; }

views.py

AnonymousUser

urls.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

卷曲命令

urlpatterns = [
    url(r'^$', handle_request.as_view()),
    url(r'^db', hello.views.db, name='db'),
    url(r'^admin/', include(admin.site.urls)),
]

将用户名和密码传递给基于类的django视图的正确方法是什么?

0 个答案:

没有答案