Top 9 Django Concepts - Part 2
Tags: webdev, python, beginners, career
Published: 2019-08-19 01:21:51

---
title: Top 9 Django Concepts - Part 2
published: true
description: The 2nd part of a 3 part series on 9 concepts of Django to help any aspiring Django developer to accelerate their learnings  
tags: webdev, python, beginners, career
canonical_url: https://www.maxongzb.com/top-9-django-concepts-part-2-5-mins/
---

![Photo by 🇸🇮 Janko Ferlič - @specialdaddy on Unsplash](https://thepracticaldev.s3.amazonaws.com/i/ekqhqji80mi4bkllv363.jpg)

# Introduction
![undraw ideas s70l][1]

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][2]

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. 

Lastly, it will be to use either [Class-Based Views][3] vs [Function-Based Views][4].

# Essential Django Commands
![undraw progress tracking 7hvk][5]

So here are some of the basic commands you will use when you are developing in Django.

## Creating a new Django Project
![undraw all the data h4ki][6]

This is the first command that you will encounter when you are creating a Django project for the first time. 

```python
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][7] in the Django documentation.

## Starting the Django Web Server
![undraw start building vqhd][8]

By default, all Django projects are shipped with a development web server.

This is used to test out your website before you deploy it in a production environment using a production-level web server like [Gunicorn][9] or [uWISGI][10] or [Mod WISGI][11].

To start the Django web development server, you have to enter the following command:

```python
python manage.py runserver
```

By default, Django runs on an IP address of `127.0.0.1` and the port number of `8000`. 

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
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.

## Creating a Django Application
![undraw complete design ongo][12]

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
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.

## Creating & Updating Database Tables
![undraw personal data 29co][13]

In Django, database tables are represented as a **model**. 

Which could be founded in each Django application's `models.py` file. 

Details on how to create a model could be found on [Creating Models][14] in the Django documentation.

Once a model has been created in the `models.py`. 

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 `version`:

```python
python manage.py makemigrations
```
The second command is called `migrate`. 

Which applies all migrations to the database to either create a new table or update an existing table. 

For further details about the `migrate` or `makemigrations` command you can go to [Creating Models][14] that is founded in the Django documentation

## Accessing Django Shell
![undraw hacker mind 6y85][15]

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][16].

# Using Front-end Framework vs Django's Template?
![undraw design sprint x3eb][17]

Due to the exploding popularity of Javascript web frameworks that are used for front-end development.

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:
* What are the project requirements?
* Who is in the project? Is it yourself or a team of developers that includes a front-end developer?
* What is your experience in working with Vue, React or Angular? 

If the project does not require you to work with front-end web frameworks like Vue, React or Angular. 

I suggest that you stick with Django's default template system and integrate it with prebuilt [bootstrap themes][18] or [bootstrap examples][19] to speed up the development process.

If your work requires Django to be a **backend system**. 

You should start to look at building RESTful APIs using [Django REST Framework][20] to support the front-end developer with your APIs.

# Class-Based View vs Function-Based View
![undraw share opinion jpw0][21]

There is a [Debate][22] between the use of [Class-Based Views (CBV)][3] or [Function-Based Views (FBV)][4].

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.

# Conclusion
![undraw review fkgn][23]

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.

If you like my article, please **sign up** for Max [Adventurer's Newsletter](http://eepurl.com/dOUoUb) for awesome content I stumble across weekly in **Python**, **Startup** and **Web Development**.

You can also **follow** me to get the **latest** update of my article on **Dev**

Besides that I looking to help out to **mentor** anyone who is interested to break into a startup. 

My available time is from **9 pm to 2 am GMT+8**, see you soon!!!. 

This post was originally posted on Max's blog at [Top 9 Django Concepts - Part 2 : 5 Mins](https://www.maxongzb.com/top-9-django-concepts-part-2-5-mins/) and [Photo by 🇸🇮 Janko Ferlič - @specialdaddy on Unsplash](https://unsplash.com/photos/sfL_QOnmy00)

# References
* [Class-Based Views][3]   
* [Function-Based Views][4]
* [Create a new project][7]
* [Gunicorn][9]
* [uWISGI][10] 
* [Mod WISGI][11]
* [Creating Models][14]
* [Django ORM Querysets By DjangoGirls][16]
* [bootstrap themes][18] 
* [bootstrap examples][19] 
* [Django REST Framework][20] 
* [Debate][22]
* [Class-Based Views (CBV)][3]
* [Function-Based Views (FBV)][4]
* [The Top 5 Most Used Django Commands][24]
* [Illustrations By unDraw][25]


[1]: //images.ctfassets.net/ly2f59p4unnn/3YD8xVEIN3uNvKhkqVg1gk/83e1299dbb3280e7e2bc2a10db6b14d8/undraw_ideas_s70l.png
[2]: https://www.maxongzb.com/top-9-django-concepts-part-1-4-mins/
[3]: https://simpleisbetterthancomplex.com/series/2017/10/09/a-complete-beginners-guide-to-django-part-6.html#class-based-view
[4]: https://simpleisbetterthancomplex.com/series/2017/10/09/a-complete-beginners-guide-to-django-part-6.html#function-based-view
[5]: //images.ctfassets.net/ly2f59p4unnn/82sBpZHBRS9hWPLh3ZCld/84bc08e5efe27b65e07811b85e20e06f/undraw_progress_tracking_7hvk.png
[6]: //images.ctfassets.net/ly2f59p4unnn/71PZmGgxGxu9Q7mbOGjLcb/e405531e70f4513e2bf088e9e96d34f1/undraw_all_the_data_h4ki.png
[7]: https://docs.djangoproject.com/en/2.2/intro/tutorial01/#creating-a-project
[8]: //images.ctfassets.net/ly2f59p4unnn/XprFWpUNP0sM3MX3VOT5J/2afeab748d8970005df1d931a7bdb75b/undraw_start_building_vqhd.png
[9]: https://gunicorn.org/
[10]: https://uwsgi-docs.readthedocs.io/en/latest/
[11]: https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/modwsgi/
[12]: //images.ctfassets.net/ly2f59p4unnn/2Mbjd3q4lal1BBWD2PZ53o/18318fd51fb3dade014a04f16b2035fb/undraw_complete_design_ongo.png
[13]: //images.ctfassets.net/ly2f59p4unnn/2VnuJEklIPv7W0k4BuFrjw/d79c376eec559c24289a745ff878fcdf/undraw_personal_data_29co.png
[14]: https://docs.djangoproject.com/en/2.2/intro/tutorial02/#creating-models
[15]: //images.ctfassets.net/ly2f59p4unnn/5W6Pxp9TksL8lvUaOjaGXB/d26e77abc02d435a1f1acde743dc7bcb/undraw_hacker_mind_6y85.png
[16]: https://tutorial.djangogirls.org/en/django_orm/
[17]: //images.ctfassets.net/ly2f59p4unnn/1GsYiymeguLwrbkJq8RaWu/189bcd4d09492e0af5372ad490550d60/undraw_design_sprint_x3eb.png
[18]: https://themes.getbootstrap.com/
[19]: https://getbootstrap.com/docs/4.3/examples/
[20]: https://www.django-rest-framework.org/
[21]: //images.ctfassets.net/ly2f59p4unnn/3JDTj79FN1z1fghHHR0RmH/629ce64a8491ad56dfad5fe57ebf65b3/undraw_share_opinion_jpw0.png
[22]: https://simpleisbetterthancomplex.com/article/2017/03/21/class-based-views-vs-function-based-views.html
[23]: //images.ctfassets.net/ly2f59p4unnn/6cor0id0xLim3nnJ6NnTaD/d1963a0c53c2119532c2c34805547878/undraw_review_fkgn.png
[24]: https://www.codingforentrepreneurs.com/blog/the-top-5-most-used-django-commands
[25]: https://undraw.co/illustrations