Django Modularisation

Photo by Jan Huber on Unsplash

Why not to develop all in the main module. Ohhhh? That will be cumbersome when you go for larger scale applications or projects. Modularisation will be easier in django.

First Let’s make the project named django_modules and make and a module django_app (these modules are called as apps in django). Make sure that you have installed django in your machine.

Then you will get following project structure.

Let’s register the application in django_modules/settings.py as follows.

Then you can make django_app/urls.py on the module to isolate its urls and views.

First let’s make a small view in django_app/views.py .

Then add this view to a url in django_app/urls.py .

The final step is to add your modules url file to the project url file as follows. I have added in django_modules/urls.py .

Then run the application using python manage.py runserver and when you go to the http://127.0.0.1:8000/app/test it will show “Hi” message.

If you get error running python manage.py runserver use python3 manage.py runserver .

By modularising you can break your application in to several modules which will help you to understand the code easily and maintain the code easier.

Hopefully this is helpful.

If you have found this helpful please hit that 👏 and share it on social media :).