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.
.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
Steps to creating an API
- Go into the directory with
- Run command to create a new app for your new API:
python manage.py startapp api
- Update the URLConf and include the URLs for your API:
url(r'^api/v1/', include('api.urls', namespace="api")),
- Add some files in your
- 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.
- Request Methods
- Basic Authentication
- JQuery Integration
- AngularJS Integration