Python 我收到一个错误:rest#u framework.request.WrappedAttributeError:&x27;CSRFCheck&x27;对象没有属性';处理请求';

Python 我收到一个错误:rest#u framework.request.WrappedAttributeError:&x27;CSRFCheck&x27;对象没有属性';处理请求';,python,django,django-rest-framework,Python,Django,Django Rest Framework,url.py api/views.py from django.conf.urls import url from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from .views import home from posts.views import PostListView urlpatterns = [

url.py

api/views.py

from django.conf.urls import url
from django.contrib import admin 
from django.conf import settings 
from django.conf.urls.static import static 
from .views import home 
from posts.views import PostListView 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls),
    url(r'^$', PostListView.as_view(), name='home'), 
    url(r'^post/', include('posts.urls', namespace='post')), 
    url(r'^api/post/', include('posts.api.urls', namespace='post-api')), 
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
api/serializers.py

from rest_framework import generics

from posts.models import Post
from .serializers import PostModelSerializer

class PostListAPIView(generics.ListAPIView):
    serializer_class = PostModelSerializer

    def get_queryset(self):
        return Post.objects.all()
api/url.py

from rest_framework import serializers
from posts.models import Post

class PostModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Post
        field = [
            'user',
            'content'
        ]
错误:


文档声明Django Rest框架,尽管在Django1.11.6中实际引入了
CSRFCheck的
process\u request()
方法

您正在使用的Django版本(1.10.3)对于您的Django Rest框架版本来说太旧了

您应该将Django升级到1.11.6版或更高版本

from django.conf.urls import url, include
from django.contrib import admin

from django.conf import settings
from django.conf.urls.static import static
from .views import home
from posts.views import PostListView


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', PostListView.as_view(), name='home'),
    url(r'^post/', include('posts.urls',  namespace='post')),
    url(r'^api/post/', include('posts.api.urls',  namespace='post-api')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


升级到1.11.16修复了这个问题。我不介意升级Django,但我需要知道为什么我突然看到这个错误。在此之前,它使用的是1.10。除了我的产品版本工作正常外,我发现问题出在我的本地环境中。我在使用rest_framework 3.9.1时升级到django 1.11.6,遇到了同样的挑战。但这并没有解决我的问题。我在这里提出了一个解决方案
from django.conf.urls import url, include
from django.contrib import admin

from django.conf import settings
from django.conf.urls.static import static
from .views import home
from posts.views import PostListView


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', PostListView.as_view(), name='home'),
    url(r'^post/', include('posts.urls',  namespace='post')),
    url(r'^api/post/', include('posts.api.urls',  namespace='post-api')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
pip install --upgrade django  # Upgrade to the latest Django version
pip install --upgrade django==1.11.6  # Upgrade to version 1.11.6