The previous article recorded some operations of the Django project. The data inserted part was operated manually in shell. How nice it would be to have a graphical interface to manage our data ~
Django has thought that you will need this function. with simple configuration, you can use the background module provided by Django to manage our data.
In the URL module, tianjian Admin. autodiscover () is used to automatically initialize the function.
from django.conf.urls import patterns, include, urlfrom django.contrib import adminadmin.autodiscover() urlpatterns = patterns(‘‘, # Examples: # url(r‘^$‘, ‘project.views.home‘, name=‘home‘), # url(r‘^blog/‘, include(‘blog.urls‘)), url(r‘^admin/‘, include(admin.site.urls)), url(r‘^author/$‘, ‘blog.views.show_author‘), url(r‘^book/$‘, ‘blog.views.show_book‘),)
The admin path is included below by default. Now you can start the project and enter the background. the user name and password are the Administrator we entered at syncdb.
However, by default, only users and groups are displayed, and data structures defined by ourselves are not included. Therefore, we need simple configuration.
Edit Admin. py in the app directory, that is, the blog directory, and register our models.
from django.contrib import adminfrom blog.models import Author, Book# Register your models here. admin.site.register(Author)admin.site.register(Book)
OK. In this way, you can see the following interface from 127.0.0.1/admin/enter the user name and password.
Click authors to display the management interface and the author we added.
Of course, the default background may not be suitable for creating some applications. You may need to write the appropriate background by yourself, and the default background also has various parameters to facilitate data retrieval, adding, and sorting. Write it here first, continue to study in depth, and then record it.
Explore Django admin (1)