[Django]-How to get xml format in Django Rest Framework

5👍

Actually your settings.py is missing the xml parser config.

  1. install rest_framework_xml : pip install djangorestframework-xml
  2. Update INSTALLED_APPS in settings.py
INSTALLED_APPS = [
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  'rest_framework',
  'rest_framework_xml',
  'books',
  'users',
]
  1. Add xml parser in settings.py:
REST_FRAMEWORK = {
  'DEFAULT_PARSER_CLASSES': (
    'rest_framework_xml.parsers.XMLParser',
  ),
    'DEFAULT_RENDERER_CLASSES': (
    'rest_framework_xml.renderers.XMLRenderer',
  ),
}
👤Dhia

0👍

It is adviceable that you use virtual environment. Check how to use pipenv here

Leave a comment