urls.py
private readonly ClientIds _clientIds;
public MyService(IOptions<ClientIds> clientIds)
{
_clientIds = clientIds.Value;
}
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 / urls.py
from rest_framework import serializers
from posts.models import Post
class PostModelSerializer(serializers.ModelSerializer):
class Meta:
model = Post
field = [
'user',
'content'
]
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 .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'),
]
答案 0 :(得分:18)
文档指出Django Rest Framework works with Django versions 1.11, 2.0, 2.1,尽管process_request()
的{{1}}方法实际上是在Django 1.11.6
对于您的Django Rest Framework版本而言,您正在使用的Django版本(1.10.3)过旧。
您应该将Django升级到版本 1.11.6或更高版本。
CSRFCheck
或
pip install --upgrade django # Upgrade to the latest Django version