🍡 Django - Basics
Django is a free and open-source web framework written in Python.
Compared to, for example, Ruby on Rails:
- Django has less "magic." You are required to write more code in Django, but you also need to know less to be productive.
- Ruby on Rails is faster to ship something if the team already understands it.
- Django uses Python, and there are a lot of non-web related libraries for Python, e.g., for data science and math. If those are important to you, you might as well use Django to simplify your tech stack.
Django project consists of "apps".
- Project is a collection of apps for a particular website.
- App can be a whole web application or just part of it e.g., blog.
- App can be used by multiple projects, but not necessary.
Django apps follow the same naming conventions as Python modules.
mydjangoapp # GOOD
MyDjangoApp # BAD
my_django_app # BAD
my-django-app # BAD, WON'T EVEN WORK
For apps that won't be released separately, I prefer short names based on abbreviations like
om
orordm
for "Order Management" etc.
Some people like to use longer names likeorders
but that has the downside that you will gradually use that style less as the project grows and you introduce more complex apps to the project and writing the full name isn't feasible.
The default apps in a Django project:
django.contrib.admin
- Admin control panel functionality.django.contrib.auth
- Authentication system.django.contrib.contenttypes
- Content type management.django.contrib.sessions
- Session management.django.contrib.messages
- One-time notification framework.django.contrib.staticfiles
- Static file management.
All Django configuration is in myapp/settings.py
. By default, Django uses a local SQLite database.
When your project grows, you might split settings under a directory with
myapp/settings/__init__.py