Home > Article > Backend Development > How to implement site management in Python
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 = [ # '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', ]
<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('admin/', 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!