0
我使用帶令牌認證的django restframework。 它運行正常,當我在django開發服務器上運行它,但是當我在apache上運行它時,它失敗並出現401驗證錯誤。帶令牌認證的django-restframework在apache上返回401
# settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
)
}
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'django.contrib.admin',
'rest_framework',
'rest_framework.authtoken',
)
@api_view(['GET', 'POST'])
@authentication_classes((TokenAuthentication, SessionAuthentication, BasicAuthentication))
@permission_classes((IsAuthenticated,))
@staff_member_required
def api(request):
params = request.data
res = rest_api.get_data(params)
return HttpResponse(json.dumps(res), content_type="application/json")
如果我刪除
@permission_classes((IsAuthenticated,))
@staff_member_required
它完全可以在Apache的,但那麼它的不安全。 任何想法是什麼問題以及如何解決它?
完美。我把它放在httpd.conf中,它正在工作。謝謝哈米德。 – max