The road to Django learning - basics (1)

Table of contents

install django

create project

Project structure:

Project begining

3-MTV model (It is important to understand the MTV model)

install django

Command method:

pip install django==2.0 (now updated to version 3.0)

The download is relatively slow to solve the problem, you can change the mirror source:

pip install django==2.0 -i Simple Index

create project

django-admin startproject mysite

Go to the mysite directory to create a virtual environment:

cd mysite

python -m venv venv

Project structure:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

manage.py: manage the django command line tool, where manage.py is actually admin

Difference: django-admin will be added to the environment variable (can be used in the command prompt window)

manage.py can only be used in the project

mysite: project name ----> business logic writing, project configuration, route management place

__init__.py #Let python recognize the current directory as a package

settings.py: the configuration file of the django project

wsgi.py: the whole web server gateway interface web gateway interface, one protocol at the time, two specifications are determined.

First, multiple web service applications can be opened under the server, and the specification of how the client request reaches the service application .

Second, how does the service application return the processing result. (Service application should not be understood as a server)

Project begining

Create your first application

The created application is where the request and editing logic is actually processed

python manage.py startup app api

api: application name

Startup project

python manage.py runserver 5000 #5000 is the specified port, if not specified, the default is **8000**

3-MTV model (It is important to understand the MTV model)

  • Model: the most valuable

Django provides an abstract model layer to interact with the database in order to build and manipulate the data of your current web application

Django is most famous for orm

orm: object relation mapping (object relational mapping), and finally rom automatically operates in the database according to the object

You don't even need to create and modify tables yourself, you only care about the processing of the logic layer (view).

Disadvantages of orm: the established data table is relatively rigid. Queries are time consuming.

  • Template

    The template is provided, and the View passes the data to the template, renders the template layer, and then returns the rendered page to the client

    The template layer provides a designer-friendly syntax for rendering information to the user.

  • View

    View layer: interact directly with the user, responsible for processing the user's request and returning a response, to put it bluntly

Knowledge points need to master:

  • Install django and create

  • Understanding the MTV Model

Guess you like

Origin blog.csdn.net/weixin_52312427/article/details/127032231