Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the background management function of Django

Shulou Source: shulou.com Published: 2022-06-01 23:30:08 09月19日 Update

This article mainly explains "how to use the background management function of Django". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the background management function of Django.

Create a background administrator account (demosite) E:\ PycharmProjects\ demosite > python manage.py createsuperuserUsername: adminEmail address: alexnn@qq.comPassword:Password (again): Superuser created successfully.

Enter http://127.0.0.1:8000/admin in the browser to log in to the background management interface

Add the established data model to the background management interface for management.

Write the admin.py file under the application directory, that is, you can register the data model class you created with admin.

From django.contrib import admin# Register your models here.from .models import BlogArticles # introduces BlogArticles classes into the current environment admin.site.register (BlogArticles) # registers model classes with admin

After refreshing the page, it is shown in the figure:

Manage data records for the data model

Click the corresponding data model class on the management page to view a list of all records in the data model

If you feel that the function of the management page is not enough, you can continue to write admin.py files to add management functions.

From django.contrib import admin# Register your models here.from .models import BlogArticlesclass BlogArticlesAdmin (admin.ModelAdmin): list_display = ("title", "author", "publish") list_filter = ("publish", "author") search_fields = ("title", "body") raw_id_fields = ("author",) date_hierarchy = "publish" ordering = ['- publish', 'author'] admin.site.register (BlogArticles, BlogArticlesAdmin)

The effect after refreshing the page is as follows:

At this point, I believe you have a deeper understanding of "how to use the background management function of Django". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Management background data model function page content file interface learning practical deeper insufficient interest practical practical simple operation effect method more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology NVidia Microsoft Linux