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.