I'm trying to get xml format in Django Rest FrameWork,I tried the tutorial provided by Django Rest Framework, I'm new to django, I did the following.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'books',
'users',
]
urls.py
from django.conf.urls import url
from django.contrib import admin
from books.views import *
from users.views import *
from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^books/all/$', all_books),
url(r'^user/', get_user)
]
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html','xml'])
views.py
from rest_framework.response import Response
from rest_framework.decorators import api_view
from books.serializers import *
from books.models import *
# Create your views here.
@api_view(['GET'])
def all_books(request):
books = Book.objects.all()
serializers = BookSerializer(books,many=True)
return Response(serializers.data)
When I try to access the xml data, I Get this error by doing ?format=xml
{"detail":"Not found."}
the tutorial link http://www.django-rest-framework.org/api-guide/format-suffixes/