在我的settings.py
文件中,我对此进行了设置:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
}
现在,我创建了一个ListCreateAPIView
:
class ListSubreddits(ListCreateAPIView):
queryset = Subreddit.objects.all()
authentication_classes = (JSONWebTokenAuthentication, )
def get_serializer_class(self):
if self.request.method == 'GET':
return SubredditSerializer_detailed
if self.request.method == 'POST':
return SubredditSerializer
因此,我发送了一个仅创建content-type
标头的 POST 请求,并且 POST 请求成功。我没有提供任何 Authentication 或 Authorization 标头。我在这里想念什么?
答案 0 :(得分:1)
您必须向您的视图添加权限:
class MyImpl implements MyService{
static{
BeanFactory.register(MyService.class, new MyImpl());
}
// Rest of code
}
答案 1 :(得分:0)
将settings.py中^%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level}\s*%{JAVACLASS:class}\.%{WORD:method}\s-\s%{GREEDYDATA:log}$
的设置更改为以下内容:
REST_FRAMEWORK