How to Structure your Django Application with an API

Posted by Chris Bartos on October 16, 2017

I received an email asking how to structure your Django Project if you are using an API.

It’s common for people to want to know the best practices for structuring your code with your Django project.

People think that maybe if I can structure my project correctly, it would be easier to do X.

Sometimes your .py files can get so out of hand that you might want to break them up into smaller files.

Your API is just another Django app

But, How do you organize your API views and URLs?

You can do it pretty simply.

When I create an API using Django REST Framework, I’ll put my API code in it’s separate app and put all the views, URLs, Serializers, etc. inside that one directory. Everything is exactly the same.

I’ll update my URLs so that each route to my API starts with something like /api/v1/

Steps to creating an API

  1. Go into the directory with
  2. Run command to create a new app for your new API: python startapp api
  3. Update the URLConf and include the URLs for your API: url(r'^api/v1/', include('api.urls', namespace="api")),
  4. Add some files in your api folder:,, etc.
  5. Then, sign up for my Free Django REST Framework Email course to learn how to setup your own API.

Need help with Django REST Framework? Django REST Framework documentation a little confusing?

Join me for my FREE Django REST Framework email course:

Django REST Framework Email Course

You'll get 1 lesson everyday for 7 days.
You'll learn:

  • Serializers
  • Request Methods
  • Endpoints
  • Basic Authentication
  • JQuery Integration
  • AngularJS Integration
Powered by ConvertKit