Django-installation deployment startup project

1. The famous two modes MVC and MTV models

The famous MVC pattern in the field of Web server development

Web application layer: model (M) model is responsible for the mapping between business objects and database (ORM)

View (V) View is responsible for the interaction with the user (page)

Controller (C) The controller accepts the user's input and invokes the model and view to complete the user's request

They are connected in a plug-in, loosely coupled way.

Django's MTV pattern is essentially the same as MVC

Django's MTV is the value:

The M Model is responsible for the relational mapping (ORM) between business objects and the database.

The template (T Template) is responsible for how the page is displayed to the user (html).

The View (V View) is responsible for the business logic and calls Model and Template when appropriate.

A URL dispatcher is also required. Its function is to distribute page requests of URLs to different Views for processing, and Views then call the corresponding Model and Template.

2. Django download and basic commands

1) Download Django

pip3 install django  #Basic default installation
pip install django==1.11.7 #Select version to install
pip install django==1.11.7 -i --trusted-host #Domestic mirror installation

2) Create a django project (project) startproject (project name) This is a tool in the Django project, it can call the django shell and database, etc. This is the Django project settings file, which contains the project default settings, including database information, debug flags, and some other variables that work This is the controller responsible for mapping URL patterns to the application.

3) Create an application in the (project name) directory

python startapp blog #blog is the App name

4) Start the django project

python runserver 8090 

Our django is up and running! Can be accessed at

Simple example:

url controller:

from django.contrib import admin
from django.urls import path

from app01 import views

urlpatterns = [
    path('index/',views.index),   #Add a new record


from django.shortcuts import render

# Create your views here.

def index(request):   #index walk this function

    import datetime
    ctime=now.strftime("%Y-%m-%d %X")

    return render(request,"index.html",{"ctime":ctime})  # Template Syntax Variables


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">

<h4>current time:{{ ctime }}</h4>  #Template Syntax Variables


Access: You can visit

Posted by nomadrw on Fri, 13 May 2022 05:14:03 +0300