Django Introduction | Set 2 (Creating a Project)
Last Updated :
10 Dec, 2020
Note- This article is in continuation of Django introduction.
Popularity of Django
Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on Django framework. ( Source )
Sites like Hot Frameworks assess the popularity of a framework by counting the number of GitHub projects and StackOverflow questions for each platform, here Django is in 6th position. Web frameworks often refer to themselves as "opinionated" or "un-opinionated" based on opinions about the right way to handle any particular task. Django is somewhat opinionated, hence delivers the in both worlds( opinionated & un-opinionated ).
Django architecture
Django is based on MVT(Model-View-Template) architecture. MVT is a software design pattern for developing web application. MVT have following three parts-
- Model- Model is going to act as interface of your data. It is responsible for maintaining data.
- View- View is gonna be the interface that user see.
- Template - A template consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
Project Structure- Inside the geeks_site folder ( project folder ) there will be following files-
manage.py-This file is used to interact with your project via command line(start the server, sync the database... etc). For getting the full list of command that can be executed by manage.py type this code in command window -
python manage.py help
folder ( geeks_site ) -This folder contains all the packages of your project. Initially, it contains four files -
- _init_.py - It is a python package.
- settings.py - As the name indicates it contains all the website settings. In this file we register any applications we create, the location of our static files, database configuration details, etc.
- urls.py - In this file we store all links of the project and functions to call.
- wsgi.py - This file is used in deploying the project in WSGI. It is used to help your Django application communicate with the web server.
Create a project
Assuming you have gone through this article and have setup django successfully.
Create a new file views.py inside the project folder where settings.py, urls.py and other files are stored and save the following code in it-
Python3
# HttpResponse is used to
# pass the information
# back to view
from django.http import HttpResponse
# Defining a function which
# will receive request and
# perform task depending
# upon function definition
def hello_geek (request) :
# This will return Hello Geeks
# string as HttpResponse
return HttpResponse("Hello Geeks")
Attached Screenshot of above code -
Open urls.py inside project folder (geeks_site) and add your entry-
from geeks_site.views import hello_geeks
Add an entry in url field inside url patterns-
path('geek/',hello_geek),
Now to run the server follow these steps-
Open command prompt and change directory to env_site by this command-
$ cd env_site
Go to Script directory inside env_site and activate virtual environment-
$ cd Script
$ activate
Return to the env_site directory and goto the project directory-
$ cd ..
$ cd geeks_site
Start the server- Start the server by typing following command in cmd-
$ python manage.py runserver
Checking - Open the browser and type this url-
http://127.0.0.1:8000/geek/
Similar Reads
Django - Creating apps | Set - 2
In the previous article, we discussed why apps are important in Django project management? What are the benefits of using Django apps? In this article, we will discuss what are we going to build and how do apps play a vital role in Django projects? Project outline - We will build a localhost e-comme
2 min read
Django - Creating Apps | Set - 1
Prerequisites: Django â Dealing with warnings Why do we need apps? In Django Set 2 (Creating a Project), we saw how we can display text in our browser using Django but that is not the best and pythonic way. Django recommends using the project-app relationship to build Django projects. Any website co
1 min read
How to Create a Project in GitLab?
A popular web-based tool for the DevOps lifecycle, GitLab offers a Git repository manager. It integrates CI/CD pipelines, version control, and collaboration tools, making it a powerful tool for developers and companies. Creating a project is one of the first things you do while using GitLab. This ar
3 min read
How to Create an App in Django ?
Prerequisite - How to Create a Basic Project using MVT in Django? Django is famous for its unique and fully managed app structure. For every functionality, an app can be created like a completely independent module. This article will take you through how to create a basic app and add functionalities
4 min read
HTML Course | Starting the Project - Creating Directories
Now we have understood the important concepts of HTML, it's time to start building a structured web project. In this chapter, youâll learn how to set up directories and organize files efficiently. It is important to have a well-structured directory for both small and large projects, as it makes your
3 min read
Django Project MVT Structure
Django is based on MVT (Model-View-Template) architecture. MVT is a software design pattern for developing a web application. MVT Structure has the following three parts - Model: The model is going to act as the interface of your data. It is responsible for maintaining data. It is the logical data s
2 min read
Unity | Introduction to Interface
The article "Game Development with Unity | Introduction" introduces about Unity and how to install it. In this article, we will see how to create a new project and understand the interface of the Unity Game Editor. Creating a new project Open the Unity Hub. Click on New button at the top right. Sele
3 min read
How to Explain Your Project in an Interview: Steps and Tips
One of the most important parts of the selection process, especially for technical roles, will be the explanation of your project during an interview. Explain clearly and properly what you did at work, thus proving your technical grip, explanation of complicated ideas, collaboration effort, and cont
9 min read
Fundamental Steps For a Data Analytics Project Plan
It always seems hard to know where to start your data analytics project. At beginning of the projects, you always face some questions like What are the goals of the project? How to get familiar with the Data? What are the problems youâre trying to solve? What can be the possible solution? Which skil
5 min read
Top 10 Django Projects For Beginners With Source Code
When it comes to software development in general, all development is run by websites on the internet. Even when you arenât actively looking for web development or a Full stack developer role, having worked on Django Projects or any web development projects will substantially improve your portfolio r
9 min read