In Django admin

1. Basics

  After writing a web site with Django framework, we add data about in two ways:

    1. Add the data in the database in connection

    2. Log admin, add data into the background

  After you create a Django project, we will see a path in the url.py

# Django comes back page 
path ( ' ADMIN / ' , admin.site.urls),

  We log in directly, such as:

http://127.0.0.1:8000/admin/

2. Expansion of knowledge

2.1. Page Language replaced by Chinese

  Settings.py to set.

# LANGUAGE_CODE = 'EN-US' 
LANGUAGE_CODE = ' ZH-Hans ' # will be replaced by the admin Chinese language

2.2 How to add your own table in the admin

  Go admin.py in the registry.

from django.contrib import admin
from blog import models

# Register your models here.
# 告诉admin我有哪些表

admin.site.register(models.UserInfo)

2.3 The table name into Chinese

  When build their own table in model.py, the table names are in English, if you need to change the Chinese, went model.py next class at each table to establish their own add the following sentence, When you're done, Chinese standard behind the name is a plural form, eliminating the need to convert the complex.

    class Meta -:
         # Display Chinese name table in the admin 
        the verbose_name = ' user information ' 
        # if not this one, the admin will be displayed as "user information s", plural. 
        verbose_name_plural = verbose_name

2.4. Each field name into Chinese

  Same reason, with each field in the back brackets verbose_name = 'field name'

2.5. Understanding blank = True

  Sometimes, we set a certain field in the database can be empty, but can not be null, how to do this in the admin it? The solution is to add directly in the back of the field brackets blank = True

Guess you like

Origin www.cnblogs.com/missdx/p/11406913.html