Lessons learned building Django projects
I’ve been using Django as my go-to framework for the past few months. So far I’ve enjoyed the ride, but have learned some things that I’d like to share with you:
- During project setup, create a virtual environment for yourself to work in. Use the ‘pip freeze’ for creating a requirements.txt that helps you manage dependencies.
- Don’t use any paths within the views. Instead, use the reverse function for looking up routes that correspond to the url. This helps a lot when you run Django in a folder on a server.
- Logic should be integrated into models. I’m just getting used to this, but helps creating DRY-er code. In the next version I will be doing this for most of my dashboard functionalities.
- Use South for your database migrations. It helps moving data around when you change your models during development.
- Alias ‘python manage.py’ to ‘django’ in your bash or zsh config for easy access to functions.
- Use different settings files for development, staging and production
- When deploying, it took me a while to figure out, but it’s quite easy to use a virtual environment for your app too. I’m trying to take it one step further by exploring Docker.