Django Create Project

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django is very popular for its rapid development, scalability, clean design, and security. Django provides the solution for basic problems which every web developer faces, and it takes care of most of the hassle of web development so that a programmer does not have to write code from scratch. Django is used by many giants companies such as Instagram, Pinterest, and Spotify, etc. Django is currently at the 6th position among the frameworks based on GitHub projects and StackOverflow questions.

Installation

In this post, we will be making our first project in Django from complete scratch. The first step is to download Python. This is a programming language that is used by Django. To download Python go to the link https://www.python.org/downloads/and click on the download option. If you already have Python, you can check the version by using this command:

Python --version

After installing, to verify the installation, use this command:

Django Create Project

If this commands runs without an error, it means we have successfully installed Python. The next step is to install Django.

Before actually installing Django, we would like to create a virtual environment where we can store all our project files. Virtual Environments are very useful. They help to keep separate versions of a module for different projects without messing them up. To install the virtual environment, execute this command in your terminal or command prompt.

pip install virtualenv
Django Create Project

After creating the virtual environment, we want to create and activate this environment to use it. To create the virtual environment, go to the directory in which you want to create the environment and then type this command:

Virtualenvmyenv

This will create a new directory named myenv in your current directory. To activate this virtual environment we just created, use the command below:

Myenv\Scripts\activate

If the environment is activated, we can see the environment name on the left side of the console.

Django Create Project

After successfully creating and activating the environment, the next step is to install Django. The easiest way to install Django is by using the python package pip. To install Django run this command in your command-line interface python –  m pip install Django.

Django Create Project

To verify if Django is correctly installed in your local machine or not, execute the following command in the Python console:

Import Django
Django Create Project

If this command does not show any error and Django is installed on your computer, we can check the version of the Django installed by running the below code in the python console.

Print(Django.get_version())

The above command will print the version number of Django.

Creating Project

In Django, there is a difference between a project and an app. Every web application we create is a project, and a project is a sum of applications. An application is a code for a part of the web application, and an application can be reused to make new applications by just making some changes to it.

To start our new project, we have to auto-generate some Django code which will be the building block of our project. This code contains various settings and configurations for the Django project and app. To start creating the project, go to the directory where you want to create your project and run the following command in your command prompt.

django-adminstartprojectmyproject

It will create a project folder in which you can create the files for your apps.  The structure of this directory is:

  • manage.py: It is one of the most important files. This helps us interact with the project through the command line.
  • My project folder: This folder is the actual Python package for our project. This folder contains all the files we will use.
    • __init__.py: This is a Python package.
    • Settings.py: This file contains all the settings of the website. This file stores the configurations of database connections, any apps we create, etc.
    • Urls.py: We declare all the URLs in this file.
    • Wsgi.py: This file serves as an entry point to the WSGI servers and is used to deploy the project.
    • Asgi.py: Similar to WSGI, asgi.py is used to deploy the project in ASGI.

Setting up Database

We can connect our project to a lot of databases. Here we will use sqlite. All the settings for our project is set up in myproject\settings.py file. Database is set up in DATABASE dictionary. To create a connection with SQLite engine, the settings is:

DATABASES = {
   'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': 'database.sql',
      'USER': '',
      'PASSWORD': '',
      'HOST': '',
      'PORT': '',
   }
}

Now our project is ready to start the development server navigate to the project directory by cd myproject.

python manage.py runserver

The output of this command will be something like this in the terminal:

Performing system checks...
0 errors found
January 08, 2020 - 15:50:53
Django version 1.8, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C

This output confirms that we have done our first project successfully and have started the development server. Go to the above URL to see the default homepage.

Django Create Project

Related Topics

Django Filters

Django is a high-level python based web framework. Django is mostly used as a backend engine for websites. Nowadays, every website communicates to a database to fetch all the information...

3 minutes read.

Django Pagination

Django is an open-source free to use python based web framework. Django provides many inbuilt tools for web developers to provide rapid web development. One of these tools is pagination....

4 minutes read.

Django Image Upload

Django is a python based web framework that uses Model View Template as its architecture. Django provides really quick web development with its functionalities. While we are building a website,...

3 minutes read.

Django Celery

Django is a python-based web framework. It is an open-source and free-to-use framework. Django uses the Model View Template architecture. Django provides many functionalities to web developers. One of these...

3 minutes read.

Django Project

Django Project Let's start to use it. Each web app you want to build in Django is called a project; and a project is a collection of apps. A software is a series of...

3 minutes read.

Django REST Framework

Django REST Framework (DRF)is an open-source, powerful, and flexible toolkit used to build RESTful web APIs. It is built upon the Django framework. DRF increases the development speed. Django and...

4 minutes read.

What is Django?

What is Django? Django is a free and open-source web application framework, written in Python. A web framework is a set of components that help you develop an easier and faster website. When we...

3 minutes read.

How to create an app in Django

Create an application in Django Django is famous for its unique and fully managed application structure. For each functionality, an application can be created as a completely independent module. This article will take...

2 minutes read.

Django Logging

Every application developed has some bugs and errors. It is the responsibility of the developers to maintain the application by making it bug-free and error-free. To debug the application code...

5 minutes read.

Django vs Laravel

Django Overview Django is a Python Programming Open Source framework for web development. It was released in 2008 and was developed by two web developers named Adrian Holovaty and Simon Willison....

4 minutes read.

Django Stack

Django is a popular Python web application framework that adheres to the "batteries-included" tenet. Batteries-guiding included idea is that common functionality for creating web applications should be provided with the...

5 minutes read.

How to Implement Multiple User Types with Django

Django Framework: Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the...

3 minutes read.

Features of Django

Features of Django Offers High Security:- Django is super secure. To prove the feature, we can always take examples of lots of websites which are present worldwide and possess huge traffic. Django is secure because it covers the...

3 minutes read.

How to Uninstall Django from cmd

Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

Django Admin

To manage the content of the website, e.g., adding and deleting posts, web developers need an admin portal on the website. The admin portal allows trusted users, also knows as...

3 minutes read.

Django Tutorial

Django Introduction It is a web application framework written in a python programming language. It based on the MVT( Model View Templet) design pattern. It takes a short time to build an application...

2 minutes read.

Django Create Superuser

For managing the website, we need an Admin while creating the Django application. In order to create the admin user, create superuser command is used. The superuser is called the...

3 minutes read.

Django Framework

Django is a popular high-level open-source web development Python framework based on follows Model View Template (MVT) architecture that allows rapid development. It. It provides common functionality like Admin Interface,...

3 minutes read.

Django Model

Django Model A template is a class representing a table or collection in our DB and where each class attribute is a table or collection area. In the app / models.py, models are...

6 minutes read.

Django – Sending E-mails

Django – Sending E-mails Django comes with a light engine that is ready and simple to use to send emails. Similar to Python, you just need to import a smtplib. You just need to import django.core.mail in Django. Edit the project settings.py file to start sending emails and set  all the following options: EMAIL_HOST – server with smtp.EMAIL_HOST_USER – smtp server login key.EMAIL_HOST_PASSWORD ? Password credential for the smtp server.EMAIL_PORT – server port smtp.EMAIL_USE_TLS or _SSL – if it is secure connection then set True. Simple E-mail Sending To submit a simple e-mail, let's create it a "simpleEmail" view. from django.core.mail import...

3 minutes read.