Explore Django admin (1)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.