Home  >  Article  >  Backend Development  >  How to implement site management in Python

How to implement site management in Python

小云云
小云云Original
2018-03-30 17:03:081962browse

This article mainly shares with you the methods of implementing Python to manage the site. It mainly explains it to you in the form of code. I hope it can help you.

1. Django back-end management page

Django has a built-in back-end management page, which only needs to be configured before it can be used. This saves developers from having to wait and see after development. After the site is built, there will be the trouble of building a backend management system. .

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

<br>Added a few more lines of code:

def __str__(self):
        return self.title

    class Admin:
        pass

<br> Among them, class Admin: pass declares a management page for the current data model (the same is true for other models)

We have modified some configuration parameters in settings.py before:

INSTALLED_APPS = [
    # &#39;django.contrib.admin&#39;,
    # &#39;django.contrib.auth&#39;,
    # &#39;django.contrib.contenttypes&#39;,
    # &#39;django.contrib.sessions&#39;,
    # &#39;django.contrib.messages&#39;,
    # &#39;django.contrib.staticfiles&#39;,
    &#39;books&#39;,
]

MIDDLEWARE = [
    # &#39;django.middleware.security.SecurityMiddleware&#39;,
    # &#39;django.contrib.sessions.middleware.SessionMiddleware&#39;,
    # &#39;django.middleware.common.CommonMiddleware&#39;,
    # &#39;django.middleware.csrf.CsrfViewMiddleware&#39;,
    # &#39;django.contrib.auth.middleware.AuthenticationMiddleware&#39;,
    # &#39;django.contrib.messages.middleware.MessageMiddleware&#39;,
    # &#39;django.middleware.clickjacking.XFrameOptionsMiddleware&#39;,
]

<br>Commented out some code, now you need to release all the commented out code

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

<br>

Now the database should look like This is what it looks like.

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

<br>
url(&#39;admin/&#39;, admin.site.urls),

Then Start the server, python manage.py runserver

访问 http://127.0.0.1:8000/admin/
看到一个这样的页面:
恭喜,访问成功,具体的使用可以自己点一下看看。

The above is the detailed content of How to implement site management in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn