Django's own background management configuration

Configuration of Django's own background management

Create projects and apps

Modify profile

Database configuration

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',#Select the name of the database. Please confirm that you have this database in mysql
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': 'localhost',
        'PORT': '3306',

Application configuration


Time and language related configuration

LANGUAGE_CODE = 'zh-Hans'   # Default is English

TIME_ZONE = 'Asia/Shanghai'    # time zone

USE_I18N = True

USE_L10N = True

USE_TZ = False       # Date format setting

Create a class under the currently applied models

class Users(models.Model):

    def __str__(self):
        return self.uname

Generate migration file

python makemigrations

Execution transfer

pythin migrate

Startup project

Start project access / login required

Create administrator user password

Execute python createsuperuser
Then enter the user name and password as prompted
Then visit
Then enter the account number and password to log in
After success, you need to configure as follows

Configure the file under the current application

#  Import model
from . import models
class UsersAdmin(admin.ModelAdmin):
  # Fields to show
  list_display = ('id','uname','age','sex','email','addtime')

  #List? Editable set the default editable field
  list_editable = ['uname', 'age','email']

   #Set how many records are displayed per page. The default is 100 records
  list_per_page = 10

  #ordering sets the default sorting field. A negative sign indicates descending sorting
  ordering = ('id',)

  #Filter groups
  list_filter =('uname', 'age', 'email') 

   #Search field
  search_fields =('uname', 'age', 'email') 

  # Detailed time layered filtering
  date_hierarchy = 'addtime'

# Registering device,UsersAdmin)

Tags: Python Django Database MySQL

Posted on Mon, 02 Dec 2019 13:27:25 -0500 by Havery Jay