How Python implements the management site

Source: Internet
Author: User
This article mainly and everyone to share the Python implementation of the method of management site, mainly in code and we explain the way, hope to help everyone.

One, Django Admin page

Django has a built-in admin page that you can use only with configuration, which eliminates the hassle of developers having to do a backend management system after the site is developed.

First, we need to add a management page to our data model.

Class Publisher (models. Model):    name = models. Charfield (max_length=30)    address = models. Charfield (max_length=50) City    = models. Charfield (max_length=60)    state_province = models. Charfield (max_length=30)    Countray = models. Charfield (max_length=50)    website = models. Urlfield ()    def __str__ (self):        return Self.title    class Admin:        Pass


Add a few lines of code:

def __str__ (self):        return Self.title    class Admin:        Pass


Where class Admin:pass is to declare a management page for the current data model (the same is true for other models)

We have previously modified some of the configuration parameters in settings.py:

Installed_apps = [    # ' Django.contrib.admin ',    # ' Django.contrib.auth ',    # ' Django.contrib.contenttypes ',    # ' Django.contrib.sessions ',    # ' Django.contrib.messages ',    # ' Django.contrib.staticfiles ',    ' Books ',]middleware = [    # ' Django.middleware.security.SecurityMiddleware ',    # ' Django.contrib.sessions.middleware.SessionMiddleware ',    # ' Django.middleware.common.CommonMiddleware ',    # ' Django.middleware.csrf.CsrfViewMiddleware ',    # ' Django.contrib.auth.middleware.AuthenticationMiddleware ',    # ' Django.contrib.messages.middleware.MessageMiddleware ',    # ' Django.middleware.clickjacking.XFrameOptionsMiddleware ',]


Comment out some code and now you need to let go of the commented out code.

Then run Python manage.py migrate to create these tables, which are the tables required for permission management


Now the database should look like this.

Since it is the page, we need to configure the access path, as we did before, to open urls.py add a configuration


URL (' admin/', admin.site.urls),

Then start the server, Python manage.py runserver

Visit http://127.0.0.1:8000/admin/
To see a page like this:
Congratulations, the visit is successful, the specific use can be a little bit to see their own.

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.