Published: August 19, 2019
Welcome to part 2 of the 3 part series for Top 9 Django Concepts.
I will be covering 3 Django concepts, for those who had missed the first part of the 3 part series, you can head down to the Top 9 Django Concepts - Part 1
The first concept is essential Django commands that you will be using when developing in Django.
The second is the concept of using either a front-end like Vue, React or Angular web framework or using Django existing template system to build UI.
So here are some of the basic commands you will use when you are developing in Django.
This is the first command that you will encounter when you are creating a Django project for the first time.
django-admin startproject project-name
This command helps to create a template project folder with all the standard list of files or folders that are required for Django to run.
The folder with the same name as the project, contains configuration setting, url routing and serving configuration.
For further explanation of the default project structure of the template project.
Please head down to Create a new project in the Django documentation.
By default, all Django projects are shipped with a development web server.
To start the Django web development server, you have to enter the following command:
python manage.py runserver
By default, Django runs on an IP address of
127.0.0.1 and the port number of
You could change the IP address and the port number to serve it in a different IP address or port number by entering the following command:
python manage.py runserver ip_address:port
Once the development server is up and running, you could leave it without interfering it.
The development server has a built-in function to reload the server whenever a new code is added.
You can think of Django applications as add-on modules to do a single task for the project which forms the whole website.
Now, you create a new application by entering the following command:
python manage.py startapp appname
This command creates a new Django application with various files and folders to execute the application.
It is always recommended to split multiple features into smaller applications.
Instead of having a single big application which does everything for ease of maintenance and readability of the project.
In Django, database tables are represented as a model.
Which could be founded in each Django application's
Details on how to create a model could be found on Creating Models in the Django documentation.
Once a model has been created in the
The developer has to perform 2 commands to make changes to the database.
The first command is called
makemigration, which prepares the changes to be made to the database as migration aka
python manage.py makemigrations
The second command is called
Which applies all migrations to the database to either create a new table or update an existing table.
For further details about the
makemigrations command you can go to Creating Models that is founded in the Django documentation
By entering the following command, it will open an interactive python shell with all the Django modules loaded.
python manage.py shell
This command is useful when you plan to test out various Django's ORM queries before adding it into your Django App.
Details on how to perform various ORM queries could be founded at Django ORM Querysets By DjangoGirls.
You may encounter this dilemma when working with clients or in your work.
Ultimately, this comes down to the following list of questions I will ask myself:
If the project does not require you to work with front-end web frameworks like Vue, React or Angular.
If your work requires Django to be a backend system.
You should start to look at building RESTful APIs using Django REST Framework to support the front-end developer with your APIs.
Due to the reason that both have their pros and cons.
I would suggest you use Class-based Views only when you understand it and found the use case for using it in your project.
Which is the need to reuse and customising purposes in your project or else use Function-based View.
If you are a beginner in Django due to it's simplicity and straight forward way of presenting the logic in your code.
I hope that you gain a better understanding of various concepts that you may encounter as a Django developer.
These concepts are design or development decisions.
Which you might need to make due to the depth of knowledge required and Django's role that increasingly being used as a backend system.