django启用超级管理员
介绍 (Introduction)
If you have followed along in the Django Development series, you’ve started a Django application, connected your application to MySQL, and created the database models for the Posts
and Comments
data within your blog web application.
如果您遵循Django Development系列教程 ,那么您已经启动了Django应用程序,将应用程序连接到MySQL,并在博客Web应用程序中为Posts
和Comments
数据创建了数据库模型。
In this tutorial, we will connect to and enable the Django admin site so that you can manage your blog website. The Django admin site comes pre-built with a user interface that is designed to allow you and other trusted individuals to manage content for the website.
在本教程中,我们将连接并启用Django管理网站,以便您可以管理博客网站。 Django管理网站预先构建了一个用户界面,该界面旨在使您和其他受信任的个人可以管理网站的内容。
It is worth noting that Django’s official documentation points out that although this is ideal for an organization’s internal use, it is not recommended to build a web application around an automatically generated Django admin interface. If you find that your interface needs to be more process-centric or proves to abstract away the implementation details of database tables and fields, it would be best for you to write your own views for the admin side.
值得注意的是,Django的官方文档指出,尽管这对于组织内部使用而言是理想的选择,但不建议您围绕自动生成的Django管理界面构建Web应用程序。 如果您发现您的界面需要以流程为中心,或者被证明可以抽象出数据库表和字段的实现细节,那么最好为管理员编写自己的视图。
先决条件 (Prerequisites)
This tutorial is part of the Django Development series and is a continuation of that series.
本教程是Django开发系列的一部分,并且是该系列的继续。
If you have not followed along with this series, we are making the following assumptions:
如果您未遵循本系列文章,我们将进行以下假设:
- You have Django version 3 or higher installed. 您已安装Django版本3或更高版本。
You have connected your Django app to a database. We are using MySQL, and you can achieve this connection by following part two of the Django series, “How To Create a Django App and Connect it to a Database.”
您已将Django应用程序连接到数据库。 我们正在使用MySQL,您可以通过遵循Django系列的第二部分“ 如何创建Django应用并将其连接到数据库 ”来实现此连接。
You are working with a Unix-based operating system, preferably an Ubuntu 20.04 cloud server as this is the system we have tested on. If you would like to set up Django on a similar environment, please refer to our tutorial, “How To Install Django and Set Up a Development Environment on Ubuntu 20.04.
您正在使用基于Unix的操作系统,最好是Ubuntu 20.04云服务器,因为这是我们经过测试的系统。 如果您想在类似的环境中设置Django,请参考我们的教程“ 如何在Ubuntu 20.04上安装Django和设置开发环境” 。
As this tutorial is largely dealing with the Django Admin Interface, you may be able to follow along even if you have a somewhat different setup.
由于本教程主要涉及Django Admin Interface,因此即使设置有所不同,您也可以继续学习。
步骤1 —启用管理员 (Step 1 — Enable the Admin)
Whenever we begin doing work in Python and Django, we should activate our Python virtual environment and move into our app’s root directory. If yo