- Piotr Kurnik
To run successful Django project, you have to know the framework. In this short post I will list a few tips, that may help you in embracing the framework.
Read Django design philosophies
Read Django design philosophies periodically. I have seen projects to diverge from the desired state quite frequently. Reviewing Django design philosophy will allow to re-embrace the Django way and make your projects more maintainable and more fun to work with.
There is a philosophy behind the the Django Framework. As you are going to start working with Django, make sure you know it. Make sure you know what is your overall goal, what did the creators of the framework intended to achieve and what are the benefits of their approach. Simplicity, consistency, and loose coupling are important. Make sure you know what they mean and why would you desire them.
Knowing these design philosophies is important, because it will allow you to rule out the feature designs/implementations that are not compliant with the Django philosophy and thus allow you falling into numerous traps
Read Django books
A good Django book is a treasure. If you are new to Django, one of the best things you can do is to get a decent book about Django and just work though it. It will definitely improve your understanding of the framework, its philosophy as well as design decisions. You will learn "the Django way" and as a result, it will vastly improve your productivity, as well as it will spare the frustrations for your fellow developers. I don't have any interest in recommending this, other than saying thank you to the author, but "Two Scoops of Django" is the one you should get if you are new in the Django world.
Django pattern is your ally not your foe
One of the biggest strengths in Django is this structure. If you are onboarded on existing Django project you should be able to quickly figure out how everything works. That consistency is a treasure, because it shortens the onboarding time and improves productivity by a large margin. Respect that,or you are going to see a substantial slow-down in the speed of development, increased costs of maintenance and complicated refactoring. Above all, don't try to turn your Django project into a Flask app. And I only say this, because I've seen this multiple times.
Django has a pretty well-defined project structure. There is a place for settings, there is a place for apps. Within each application there is a place for models, urls, serializers, views as well as the bits and pieces for Admin panel and celery tasks. That is a good thing. Respect that, no need to be creative in here!
Start your Django app setup with decent set of defaults
Django is a mature project. Milions of lines of code has been created across the globe. People have been struggling with the common set of problems and they have solved them. Don't force open door. Use somebody's effort and make sure you follow most up-to-date standards for setting up a bran new Django project. Many Django templates have 90% of the things that you will ever need by default. Use them so that you will not have to reinvent the wheel every time and start solving you business challenges as soon as possible.
If you look for a decent Django project starter, look no further: https://github.com/cookiecutter/cookiecutter-django This is my favourite Django project starter and I've been using it for a long time. I find that it has everything that I use, and I really like it.
If you are using this template, you may consider supporting its author https://www.patreon.com/feldroy or via Github, as he does a great job maintaining it.
Read Django documentation
Over the years I have noticed that people don't read documentation. At the very least they don't read documentation as much as they should. I almost feels like the developers feel they are awesome enough and neglect this part. However, failure to read the documentation, leads to misconceptions, misunderstanding of the Django design, thousands of unnecessary lines of code and hundreds of thousands of dollars lost in the development time, that could be used more profitably elsewhere. If you don't have a few a ton of experience with Django, s et aside an hour a day, and go through each section carefully. I will pay off. Promise!
Create a toy project
Before you start, create a toy project. Have a look at components of the framework. Make sure you understand how everything hangs together. Learn how to write unit tests in Django, and add them early on. Following a tutorial on the internet is a decent start, however it does not mean you can become a seasoned Django developer overnight. As with everything else, getting proficient in something requires time and effort. A toy project is a good starting point, but it is just a beginning.
Don't start with just juniors onboard
Don't start with just juniors onboard. By "juniors" I mean people who don't have a few years of Django development under the belt. The seniority is always a relative thing, I know that. I have seen pretty senior people making really, really terrible decisions, just because they have lacked "the Django way", and "Django way" is earned with experience.
Another reason for not starting with just juniors onboard is Danning-Krugger effect. It takes time and effort to discriminate good and bad, beautiful and ugly, clever and silly. Junior developers don't have it, sure they will, but they need to be guided. Without a proper guidance, chances are, that your app will morph into a Flask app with Django ORM or something worse than this.
Read 12factors.net before starting a new Django project
This is less of a Django-related advice, but it's very important. Knowing 12-factor-app rules is just as vital as knowing the Django design philosophies. It's a baseline that you start with whatever problem you are trying to solve.
People have been creating, running and maintaining web applications for a long time. Over the time they have made a list of 12 rules for web application to be maintainable, scalable and secure. No matter what your language of framework is, these rules are general enough to provide you with rules that will increase the chances of your project to become a great success.
Django isn't a huge framework, but it needs to be understood. It can't be learnt overnight and completing the official tutorial is not enough to fully appreciate what it has to offer, nor is it enough to write a web application "the Django way". Following above steps however, should give you a better start in embracing the framework, and solving your business problems effectively using Django.