Django basic command

Time:2019-11-6

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

Generation migration
python3 manage.py makemigration
Execution transfer
python3 manage.py migrate

Create background administrator account
python3 manage.py 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
Shortcuts
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

The use of progressbarcontrol, a progress bar control of devexpress – Taking ZedGraph as an example to add curve progress

scene WinForm control – devexpress18 download installation registration and use in vs: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243 When using ZedGraph to add curves, the number of curves is slower if there are many cases. So in the process of adding curve, the progress needs to be displayed, and the effect is as follows     Note: Blog home page:https://blog.csdn.net/badao_liumang_qizhi […]