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 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'),
]
views.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