gpt4 book ai didi

python - 我收到错误 : rest_framework. request.WrappedAttributeError: 'CSRFCheck' object has no attribute 'process_request'

转载 作者:太空狗 更新时间:2023-10-29 20:35:39 28 4
gpt4 key购买 nike

网址.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/views.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/serializers.py

from rest_framework import serializers
from posts.models import Post

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

api/urls.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 .views import PostListAPIView
from django.views.generic.base import RedirectView


urlpatterns = [
# url(r'^(?P<pk>\d+)/update/$', PostUpdateView.as_view(), name='update'),
# url(r'^(?P<pk>\d+)/delete/$', PostDeleteView.as_view(), name='delete'),
# url(r'^(?P<pk>\d+)/$', PostDetailView.as_view(), name='detail'),
url(r'^$', PostListAPIView.as_view(), name='list'), #/api/tweet
# url(r'^$', RedirectView.as_view(url='/')),
# url(r'^create/$', PostCreateView.as_view(), name='create'),
]

View .py

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)

错误:

enter image description here

最佳答案

文档指出 Django Rest Framework works with Django versions 1.11, 2.0, 2.1 ,虽然CSRFCheckprocess_request()方法其实是在Django 1.11.6

中引入的

您使用的 Django 版本 (1.10.3) 对于您的 Django Rest Framework 版本来说太旧了。

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

pip install --upgrade django  # Upgrade to the latest Django version

pip install --upgrade django==1.11.6  # Upgrade to version 1.11.6

关于python - 我收到错误 : rest_framework. request.WrappedAttributeError: 'CSRFCheck' object has no attribute 'process_request',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53494112/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com