23

How should I integrate Django-REST-API framework in an existing application or I have to create a new project?

2 Answers 2

35

You do not need to begin a new project. The basic steps are:

  1. Install DRF, something like pip install djangorestframework
  2. Add rest_framework to your INSTALLED_APPS
  3. Define your serialisers, views and routes.

And that's it.

I suggest you follow the Quickstart and step through the Tutorial — it's pretty welcoming really.

I hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, this is the simplest way, btw, if you are worried about performance and you need some granularity I would separate both the web project and the API project and give the needed priorities to each of them. For example, if your API will be used much more than your web, use more resources to serve your API.
19

I created a short note about how to do this with the photo gallery app tutorial from the Forcier et. al. book. I'm a Django noob, so please take this stuff as not-authoritative-perhaps-not-even-good. Here's the link to the post:

https://technote.fyi/blog/2018/01/26/how-to-add-rest-api-existing-django-project/

Basically, you create a new app, then in it write code for only three files: serializers.py, views.py, and urls.py. You don't write anything in models.py. Instead, you import the models from the existing app.

You then start off by creating serializers for all the models you want to expose, and then views for those serializers, and, finally, urls to call those views.

3 Comments

I believe there's no more pdf in the link. Could you update if you will? Thank you!
The link you have shared doesn't have any pdf.
Link has been updated and the PDF has been found and attached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.