Django Learning Road 5-Admin Background Management

Brief Introduction to Admin

Django has an excellent feature, built-in Django admin background management interface, to facilitate managers to add and delete website content.

Setting Admin

The new project system has set up the background management function for us.

You can view it in my_blog/my_blog/set.py

INSTALLED_APPS = (
    'django.contrib.admin',  #Added background management function by default
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'article'
)

Also, URLs have been added to the acquired management, which can be viewed in my_blog/my_blog/url s.py.

# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'my_blog.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),  #You can use the set url to enter the background of the website
    url(r'^$', 'article.views.home'),
)

Creating Super Users

Create a superuser using the following command account (if you use Python management.py syncdb, you will be asked to create a superuser, which is outdated and no longer recommended)

$ python manage.py createsuperuser
Username (leave blank to use 'andrew_liu'): root
Email address:
Password:
Password (again):
Superuser created successfully.

Enter username, mailbox, and password to create a superuser that can now be entered in the browser 127.0.0.1:8000/admin Enter the account and password into the background management, as follows:

But you will find that there is no increase or deletion of database information. Now we add code in my_blog/article/admin.py:

from django.contrib import admin
from article.models import Article

# Register your models here.
admin.site.register(Article)

We have to tell the administration page that Article objects need to be managed.

After saving, refresh the page again. 127.0.0.1:8000/admin

Now we register the Question class with the administration page. Django knows that it should be displayed on the index page:

The customization of the appearance of the management interface and the modification of the display order are not described in detail. If you are interested, you can see the official documents.

http://django-intro-zh.readthedocs.io/zh_CN/latest/part2/

Use third-party plug-ins

Django is now relatively mature, there are many good third-party plug-ins available, these plug-ins are various, now we use a third-party plug-in to make the background management interface more beautiful, most of the third-party plug-ins can be used at present. Django Packages  In view of,

Try to use django-admin-bootstrap Beautify the Backstage Management Interface

install

$ pip install bootstrap-admin

To configure

Then modify INSTALLED_APPS in my_blog/my_blog/set.py


INSTALLED_APPS = (
    'bootstrap_admin',  #Be sure to put it in front of `django.contrib.admin'.
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'article',
)

from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    'django.core.context_processors.request',
)
BOOTSTRAP_ADMIN_SIDEBAR_MENU = True

After saving, refresh the page again. 127.0.0.1:8000/admin

Is the interface a lot more beautiful?

Keywords: Django Python Database pip

Added by utherwun on Mon, 15 Jul 2019 03:24:39 +0300