Django: How to integrate a Django Rest environment into an existing application?

How do I integrate the Django-REST-API framework into an existing application or do I need to create a new project?

+6
source share
2 answers

You do not need to start a new project. The main steps:

  • Install DRF, something like pip install djangorestframework
  • Add rest_framework to your INSTALLED_APPS
  • Define serializers, views, and routes.

What is it.

I suggest you follow Quickstart and go through the Tutorial - it is quite welcoming indeed.

I hope this helps.

+12
source

I created a short note on how to do this with the Forcier et photo gallery application tutorial. and other book. I am Django noob, so please take this material as not authoritative, and maybe not quite good. Here is a link to the message:

http://riceball.com/d/content/how-add-rest-api-existing-django-project

Basically, you create a new application and then write code for only three files: serializers.py, views.py and urls.py. You do not write anything in models.py. Instead, you import models from an existing application.

Then you start by creating serializers for all the models you want to expose, and then browsing for these serializers and finally the URLs to call these views.

+7
source

Source: https://habr.com/ru/post/971322/


All Articles