Django Tutorial
About Lesson

In this Django Tutorial we are going to learn How to Install Django, in the first we will have a few words about django web framework, after that we talk about the installation process and at the end we are going to create our first project in Django.

 

 

What is Django ?

Django is a Python Web Framework that is used for web development. Django framework uses a set of design principles that produces one of the most productive web development processes compared to many other web frameworks. also Django provides a set of tightly integrated components. all of these components are developed by the Django team itself. Django was originally  developed as an in-house framework to manage a series of news-oriented websites.  later, its code was released on the Internet and the Django team continued its development using the open source model. because of its roots, Django’s components were designed for integration, reusability, and speed from the start. Django’s database component, the Object-relational Mapper (ORM), provides a  bridge between the data model and the database engine. it supports a large set of  database systems.  in addition, Django provides a neat development environment. it comes with a lightweight web server for development and testing. when debugging mode is enabled, Django provides very through and detailed error messages with a lot of debugging information. all of this makes isolating and fixing bugs very easy. Django supports multilingual websites through its built-in internationalization  system. this can be very valuable for those working on websites with more than one language. the system makes translating the interface a very simple task.

 

 

 

Installing Django with Pip

You can use pip for the Django installation, also we are going to use Python 3.7 in this course with Django.

 

Run this command at the shell prompt to install Django with pip, make sure that you have already created a virtual environment.

 

 

Now, check whether Django has been successfully installed. run python on a terminal, import Django, and check its version, as follows:

 

 

 

Creating First Project in Django

OK now we are going to create our first project in django. Django provides a command line utility that allows you to create an initial project file structure. Run the following command from your shell or terminal.

 

This will create a Django project with the name mysite.

 

Let’s take a look at the project structure generated:

How to Install Django
How to Install Django

 

 

 

mysite/: This is your project directory, which consists of the following files:

__init__.py: Python file to allow app packages to be imported from other
directories. Note __init__.py is not a Django specific file, it’s a generic file used in
almost all Python applications.

settings.py: This indicates settings and configuration for your project and contains initial default settings.

urls.py: This is the place where your URL patterns live. Each URL defined here is mapped to a view.

wsgi.py: This is the configuration to run your project as a Web Server Gateway Interface (WSGI)                                     application.

 

 

The generated settings.py file contains the project settings, including a basic configuration to use an SQLite 3 database and a list named INSTALLED_APPS, which contains common Django applications that are added to your project by default.

 

manage.py: This is a command-line utility used to interact with your project. It is a thin wrapper around the django-admin.py tool. You don’t need to edit this file.

 

 

To complete the project setup, we will need to create the tables in the database required by the applications listed in INSTALLED_APPS. Open the shell and run the following commands:

 

 

You will see an output that ends with the following lines.

The preceding lines are the database migrations that are applied by Django. By applying migrations, the tables for the initial applications are created in the database.

 

 

 

Runing Development Server 

Django comes with a lightweight web server to run your code quickly, without needing to spend time configuring a production server. When you run the Django development server, it keeps checking for changes in your code. It reloads automatically, freeing  you from manually reloading it after code changes.

 

 

Start the development server by typing the following command Start the development server by typing the following command from your project’s root folder.

 

 

Now, open http://127.0.0.1:8000/ in your browser. You should see a page stating that the project is successfully running, as shown in the following screenshot.

Django Tutorial - How to Install Django
Django Tutorial – How to Install Django

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found