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.
Django REST Framework Email Course
You'll get 1 lesson everyday for 7 days.
- Request Methods
- Basic Authentication
- and more...
Django REST Framework Documentation got you down? Just want to get SOMETHING working?
You can learn Django REST Framework in ONE week at about 15 - 30 minutes per day (1 lesson per day for the next 7 days).
Click the button below to sign up and start learning Django REST Framework today!click here to receive the first lesson in minutes!
(once you sign up, you'll get a new lesson everyday for the next 7 days)