Creating First Django Project
By: Berk Berber
Tags: Django Rest Framework, Backend, Django, Python, Django Framework

Django is an open-source framework for creating backend applications using Python programming language. There are many hassle parts while creating Web applications and Django is taking care of all hassle parts for us. Thus, we don’t need to reinventing something by us. We can start to developer our web application fastly and deploy it easily.

Why should we use Django Framework?

Django allows developers to focus on their needs of application instead of of spending so much time on already developed components such as user interfaced admin panel, site maps, RSS feeds.

Django cares about security seriously and it has many features for taking care about security threats. Django helps developers to avoid vulnerabilities such as SQL injection, cross-site scripting, cross-site request forgery and etc.

Django can handle heavy traffic and large volumes of information. Thus, we can develop all kind of applications that we want to develop.

Django works with many major databases. We can choose whatever we would like to use between databases. Also, django allows us to use multiple databases at the same time.

Django has great community. When we have any problem while development process, we can find answers for our questions easily. There are many community platforms such as forums, channels, websites, github repositories and questions on stack overflow.

There are many developers who are contributing to django on github and who are creating new packages to make something better. If we are looking for some packages or libraries, we can easily find them on internet.

I will give you an example website which I am using while developing django projects

How to install Django?

Django is Python Web Framework and we need to install Python first. To install the python, we can use following url:

After the installation .exe file, we need to run it and when we will show a screen as shown in the below. In this screen, we need to select both two options which are in red rectangle.

When installation has finished, we need to open or command line and run the “python — version” command. If we see our python version which we have installed, that means Python has been installed successfully.

After we have successfully installed the python, we can install Django by using pip. To install Django with pip, we can open our command line and run the following command.

python -m pip install Django

After the installation has finished, you will get a message about that Django has been successfully installed.

If we would like to test or learn the version of Django, we can run “python -m django --version” command on command line. This command will give us version of django if we have successfully installed it.

First, let’s check the django version and create a new django project.

Inside of red rectangle, you can see how to check django version which we have installed.

To start a new project, we should run “django-admin startproject <project_name>” command.

When we run this command, command line will not return anything to us if operation is successful.

What are the files in project folder?

When we create our project and open it on Visual Studio Code or any other compiler that you use, we will see following project structure.

Let’s examine these files one by one:

manage.py: This file is command line utility of the project. When we want to run some commands for our project such as deploying, running server, migrating databases or creating super users for admin panel, we will use this file on command line.

This file is command line utility of the project. When we want to run some commands for our project such as deploying, running server, migrating databases or creating super users for admin panel, we will use this file on command line. FirstProject/__init__.py: This file will be empty and we won’t do anything with that file. Its only purpose is telling Python that the folder contains Python codes.

This file will be empty and we won’t do anything with that file. Its only purpose is telling Python that the folder contains Python codes. FirstProject/settings.py: This file is the configuration file of the project. Database connection information, installed applications, middleware applications, django email settings, production settings and many other settings will be in this file.

Note: There is a SECRET_KEY in this file. Django is using this value for cryptographic signing. For the project security, we shouldn’t disclose this information with anybody else.

This file is the configuration file of the project. Database connection information, installed applications, middleware applications, django email settings, production settings and many other settings will be in this file. There is a SECRET_KEY in this file. Django is using this value for cryptographic signing. For the project security, we shouldn’t disclose this information with anybody else. FirstProject/urls.py: This file contains project level URL information for routing. This file will be the single point of source for finding Endpoints once the HTTP Requests come from the client side.

This file contains project level URL information for routing. This file will be the single point of source for finding Endpoints once the HTTP Requests come from the client side. FirstProject/wsgi.py: This file contains the configuration of wsgi application. This file will be used to run django application. And also this file is pointed in settings.py file using the ‘WSGI_APPLICATION’ setting.

How to run server?

Django has very good feature which is built-in server. We don’t need to install any other server to test our app and we can just run one command and test our application on our local.

To start server on our device, we can run the following command. (I showed the command in the below picture with the orange rectangle).

Url which I have mentioned in red rectangle shows us the url which our project will be run on local device. As a default, django runs the project on “http://127.0.0.1:8000/".

If everything goes fine, we should see the following screen on our browser when we want to open this url.