Django basic command


Create project
Django admin startproject project name
Create application
Django admin startapp application name

Generation migration
python3 makemigration
Execution transfer
python3 migrate

Create background administrator account
python3 createsuperuser

Django database

General attribute
DB column =’name’specifies the name in the database
Default = 0 specifies the default value
Null = false non NULL constraint, null can be null when it is true
Blank = false form non empty constraint
Db_index = false set index
Primary = false set primary key
Unique = false unique constraint

data type
Autofield() primary key
Boolean field()
Nullboolean field(), none
Charfield (max [length = 20) string
Textfield(), large text string, 4000+
Integerfield() ‘
Floatfield(), floating point

Decimalfield (max? Digits = none, financial accuracy, max? Digits,
Decimal place = none) decimal place

DateField (auto now = false, date, auto now keeps setting the current time automatically every time
Auto? Now? Add = false,) auto? Now? Add automatically sets the time of the first creation

Timefield(), the same parameter as DateField
Datetimefield(), datetime, with the same parameters as DateField
Filefield() upload file
Imagefield() upload picture


Word understanding
URLs links
View view
Contrib build
Decorators decoration
Core core
Upload file

from Django.conf import settings

1. URLs related operations
From django.urls import path, re? Path (when using regular), include
From Django. URLs import reverse / / note the difference between reverse and another reversed. The former needs to explicitly import and resolve the address by name, while the latter is built-in without import; both functions are different.

2. Httpresponse generation
from django.shortcuts import render, HttpResponse, redirect
From Django. HTTP import jsonresponse / / respond to a content type: text / JSON returns a JSON response message. The corresponding browser does not need to solve the JSON problem

3. Component auth
From django.contrib import auth / / contrib means: component
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required

4. Component forms
from django import forms
from django.forms import widgets
From django.core.exceptions import validationerror / / the exception definitions of Django are all in the django.core.exceptions module, which is used to customize hooks.
From Django. Forms import modelform / / if the field data of a form is mapped to a Django models by using, then a modelform can help you save a lot of development time. Because it will build a form instance, along with building the appropriate field and field attributes, and use this build information from a model class
from django.core.files.uploadedfile import SimpleUploadedFile

5. Mail component
from django.core.mail import send_mail

6. Model component
from django.db import models
from django.db.models import F, Q
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import User
From django.db import transaction – using model to do database transaction

7. Pager related
from django.core import paginator

8. Django admin site
from django.contrib import admin
from django.contrib.admin import ModelAdmin

9. View related
From django.view import view for media access to built-in views

10. Middleware
from django.utils.deprecation import MiddlewareMixin

11. Template template related
From Django import template – custom tags and filters need to be used

Recommended Today

Configure Apache to support PHP in the Apache main configuration file httpd.conf Include custom profile in

In Apache’s main configuration file / conf/ http.conf Add at the bottom Include “D:workspace_phpapache-php.conf” The file path can be any In D: workspace_ Create under PHP file apache- php.conf file Its specific content is [html] view plain copy PHP-Module setup LoadFile “D:/xampp/php/php5ts.dll” LoadModule php5_module “D:/xampp/php/php5apache2_2.dll” <FilesMatch “.php$”> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch “.phps$”> SetHandler application/x-httpd-php-source </FilesMatch> […]