Django Introduction | Set 2 (Project creation)

Python Methods and Functions

Popularity of Django
Django is used in many popular sites such as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic, etc. There are more 5,000 online sites. ( Source )
Sites like Hot Frameworks, measure the popularity of a framework by counting the number of GitHub projects and StackOverflow questions for each platform, with Django in 6th position here. Web frameworks often refer to themselves as "opinionated" or "unconvinced" based on opinions about the right way to solve any particular problem. Django is somewhat cocky, hence delivers in both worlds (cocky and unconvinced).

Django architecture
Django is based on MVC (Model-View-Controller) architecture. MVC — it is a software design pattern for web application development. MVC has the following three parts -

  • Model - The model will act as an interface to your data. He is responsible for maintaining the data.
  • View- View is going to be the interface that the user see.
  • Controller- Controller transmits information between the model and the view.

Project structure — inside the geeks_site folder (project folder) the following files will be located:

  • — This file is used to interact with your project through the command line. string (start server, sync database, etc.). For a complete list of commands that can run, enter this code at the command line -
     $ python help 
  • folder (geeks_site) — this folder contains all packages for your project. Initially it contains four files — 
    • — this is a Python package.
    • — As the name suggests, it contains all of the site's settings. In this file we register any applications we create, the location of our static files, database configuration details, etc.
    • — In this file we store all project references and functions to call.
    • — This file is used when deploying a project to WSGI. It is used to help your Django application communicate with the web server.

Create a project
Assuming you went through

# HttpResponse is used for
# pass information
# return to view

from django.http import HttpResponse

# Definition of fu the function that
# will receive the request and
# perform the task depending on
# after function definition

def hello_geek (request) :


# This will return Hello Geeks

  # string as HttpResponse

return HttpResponse ( " Hello Geeks " )

  • Open inside the project folder (geeks_site) and add the
    • Import hello_geek function and from the file.
       from geeks_site.views import hello_geeks 

    • Add an entry in the URL field inside the URL template-
       path ('geek /', hello_geek), 

  • Now, to start the server, follow these steps:
  • Checking — open your browser and enter this URL -