Python Web Development Libraries 简明教程
Django Framework
在本章中,我们将详细讨论 Django 框架。
In this chapter, we will discuss about Django Framework in detail.
Django 是一个用于构建 Web 应用程序的 MVT Web 框架。巨大的 Django Web 框架包含很多“内置信息”,开发者常常惊叹于所有这些是如何协同工作的。添加这么多内置信息的原理是将通用 Web 功能放入框架本身,而不是作为单独的库添加。
Django is an MVT web framework that is used to build web applications. The huge Django web-framework comes with so many “batteries included” that developers often get amazed as to how everything manages to work together. The principle behind adding so many batteries is to have common web functionalities in the framework itself instead of adding latter as a separate library.
Django 框架流行的主要原因之一是它拥有庞大的 Django 社区。社区如此庞大,以至于专门为其创建了一个网站,让来自各地的开发者可以开发第三方包,包括身份验证、授权、功能齐全的 Django 驱动的 CMS 系统、电子商务插件等等。你尝试去开发的东西很有可能已被其他人开发出来了,你只需要将那个整合到你的项目中即可。
One of the main reasons behind the popularity of Django framework is the huge Django community. The community is so huge that a separate website was devoted to it where developers from all corners developed third-party packages including authentication, authorization, full-fledged Django powered CMS systems, e-commerce add-ons and so on. There is a high probability that what you are trying to develop is already developed by somebody and you just need to pull that into your project.
Why should you use Django?
Django 的设计是为了鼓励开发者快速、干净、实用地设计地开发网站。Django 以其实用的方式来完成工作而从众多框架中脱颖而出。
Django is designed in such a way that encourages developers to develop websites fast, clean and with practical design. Django’s practical approach to getting things done is where it stands out from the crowd.
如果你计划构建一个高度可定制的应用程序,比如社交媒体网站,Django 是最佳的框架之一。Django 的优势在于它在用户之间的交互以及共享不同类型媒体的能力。Django 的一大优势在于其利用大型社区支持的能力,这给了你高度可定制的第三方即用型插件,用于你的应用程序。
If you’re planning to build a highly customizable app, such as social media website, Django is one of the best frameworks to consider. Django strength lies in its interaction between users or its ability to share different types of media. One of the great advantage of django is its ability to utilize large community-based support which gives you highly customizable third-party ready to use plugins in your applications.
以下是选择 Django 用作 Web 开发的十大理由−
Below are the top ten reasons to choose Django for web development −
Python
Python 是公认的最容易学习的编程语言之一,因为它有简单的语言结构、流结构和简单的语法。它非常通用,既能运行网站,也能运行桌面应用程序和嵌入到许多设备中的移动应用程序,并作为一种流行的脚本语言用于其他应用程序。
Python is arguably one of the easiest programming languages to learn because of its simple language constructs, flow structure and easy syntax. It is versatile and runs websites, desktop applications and mobile applications embedded in many devices and is used in other applications as a popular scripting language.
Batteries Included
Django 带有通用的库,这对于构建诸如 URL 路由、身份验证、对象关系映射器 (ORM)、模板系统和 db 架构迁移之类的通用功能非常重要。
Django comes with common libraries which are essential to build common functionalities like URL routing, authentication, an object-relational mapper (ORM), a templating system and db-schema migrations.
Built-in admin
Django 有一个内置的管理界面,让你可以处理你的模型、用户/组权限,以及管理用户。有了模型界面,除了高级数据库功能以外,就不再需要单独的数据库管理程序。
Django has an in-built administration interface which lets you handle your models, user/ group permissions and to manage users. With model interface in place, there is no need for a separate database administration program for all but advanced database functions.
Doesn’t get in your way
创建一个 Django 应用程序不会添加任何样板代码和不必要的功能。没有强制要求导入、第三方库以及 XML 配置文件。
Creating a Django application adds no boilerplate and no unnecessary functions. There’s no mandatory imports, third-party libraries and no XML configuration files.
Scalable
Django 是基于 MVC 设计模式 的。这意味着所有实体,如数据库 (database)、后端和前端代码,都是独立的实体。Django 允许我们将代码从静态媒体中分离出来,包括图片、文件、CSS 和 JavaScript,它们构成了你的网站。
Django is based on MVC design pattern. It means that all the entities like db (database), back-end and front-end code are individual entity. Django allows us to separate code from the static media including pictures, files, CSS and JavaScript that make up your site.
Django 支持用于 Web 服务器、缓存、性能管理、集群和平衡的第三方库的完整列表。Django 提供的优点之一是对主要的电子邮件和消息应用程序和服务的支持,如 ReST 和 OAuth。
Django supports a full list of third-party libraries for web servers, caching, performance management, clustering and balancing. One of the advantages Django provides is the support for major email and messaging applications and services like ReST and OAuth.
Battle tested
Django 在 2005 年首次开源。在 12 年的发展之后,Django 现在不仅运行新闻发布网站,而且还运行 Pinterest、Instagram、Disqus、Bitbucket、EventBrite 和 Zapier 等主要全球性企业的全部或部分业务。这使得其成为一种强大且可靠的 Web 框架,供开发者使用。
Django was first open-sourced in 2005. After 12 years of growth, Django now not only runs news publishing websites but also runs all or part of major global enterprise like Pinterest, Instagram, Disqus, Bitbucket, EventBrite and Zapier. This makes it a robust and reliable web framework to work with.
Huge package support
由于它有很大的社区支持和庞大的开发者网络,因此你打算做的任何事情很可能以前都已完成过。大量的国际开发者社区通过将他们的项目作为开源包发布,为社区做出贡献。
Because of its large community support and huge developers network, there is a high possibility that whatever you intend to do might have been done before. Large international community of developers contribute to the community by releasing their projects as open-source packages.
这些项目的其中一个资料库是 Django 包网站。目前,Django 包列出了超过 3400 个用于我们在 Django 项目中使用的可重复使用的 Django 应用程序、网站和工具。
One such repository of these projects is Django Package site. Currently, Django packages list over 3400 plus reusable Django apps, sites and tools to use in our Django projects.
Actively developed
与开放源代码项目相关的最大风险之一是其可持续性。我们无法确定它是否能够持续很长时间。
One of the biggest risks associated with open source project is its sustainability. We cannot be sure if it lasts long.
Django 没有此类风险,因为它已经存在 12 年了。它持续发布、提供更新/更好的版本,其活跃社区每天都在壮大,并且拥有一个由自愿贡献者组成的大核心团队,他们每天都维护和改进代码库。
There is no such risk with Django as it is 12 years old. Its consistent releases, newer/better versions and active community is growing every-day with a large core team of voluntary contributors who maintains and improve the code base every-day.
Stable releases
像 Django 这样的开放源代码软件项目在很多情况下都会积极开发,并且比竞争性的专有软件更安全,因为许多开发人员每天都在开发和测试它。但是,开放源代码软件项目的缺点是缺少可供商业上可行的开发使用的稳定代码库。
Open-source software projects like Django are, in many cases, actively developed and more secure than competing proprietary software as many developers are developing and testing it every day. However, the drawback of an open-source software project is the absence of a stable codebase to commercially viable development.
在 Django 中,我们有软件的长期支持 (LTS) 版本和一个明确的发布流程,如下图所示:
In Django, we have Long Term Support (LTS) versions of the software and a defined release process as shown in the below image −

Who’s Using Django?
由于 Django 独一无二的优势,有许多流行网站都使用 Python 构建在 Django 框架之上。以下是基于 Django 全部或部分构建的一些主要网站。
Because of the Django’s unique strength, there are multiple popular websites which are built with Python on top of the Django framework. Below are some of the major sites which are fully or partially built based on Django.
Disqus
它是全球最受欢迎的博客评论托管网站之一。它可以通过 Disqus 轻松地与大多数流行的 CMS(内容管理系统)集成,例如 WordPress 和许多其他系统。通过满足超过 5000 万用户群的需求,Django 可以让网站所有者与其社区取得联系。
It is one of the most preferred blog comment-hosting sites globally. It is easy to integrate with most popular CMS (content management systems) like WordPress and many others through Disqus. Handling a user-base of over 50 million, Django is able to satisfy the site owners to reach out to their communities.

The Onion
洋葱新闻网为他们的讽刺报纸提供了一个在线场所,Django 为它提供了框架。
The Onion website which provide an online venue for their satirical newspaper, Django provides the framework for it.

Bitbucket
Bitbucket 类似于 GitHub,是一个版本控制存储库托管服务。Bitbucket 与 GitHub 之间的唯一区别在于 Bitbucket 托管 Mercurial 存储库,而 GitHub 托管 Git 存储库。由于数百万用户使用 Bitbucket,并且 Bitbucket 提供的所有服务(例如创建存储库、推送代码、添加协作者、提交、提交请求等)都必须稳定可靠。Django 负责运行 Bitbucket 网站。
Bitbucket is like GitHub, a version control repository hosting service. The only difference between Bitbucket and GitHub is that Bitbucket hosts mercurial repositories whereas GitHub hosts git repositories. As millions of users are associated with Bitbucket, and all the services which bitbucket provides (like create a repo, push your code, add collaborators, commits, pull request, etc.) has to be stable. Django is responsible for running the bitbucket site.

Instagram 是一款社交网络应用,专为那些喜欢与所有朋友分享照片和视频的人打造。目前 Instagram 上有很多名人,以便与粉丝们保持更密切的联系。Django 框架也在运行 Instagram。
Instagram is a social networking app built especially for those who love to share photos and videos to all their friends. Currently there are a lot of celebrities on Instagram so as to stay closer to their fans. Django framework is running the Instagram too.

Mozilla Firefox
继 Google Chrome 之后,Mozilla 浏览器是全球使用第二广泛的浏览器。现在 Mozilla 的帮助页面是使用 Django 框架构建的。
Second most widely used browser in the world after Google Chrome is the Mozilla browser. Now the help page of Mozilla is built with Django framework.

全球数百万用户通过 Pinterest 发现他们的新想法和灵感。Pinterest 使用 Django 框架(根据其要求进行修改)来运行它。
Millions of users around the globe discover their new ideas and inspiration from Pinterest. Pinterest is using the Django framework (done modification as per their requirement) to run it.

NASA
美国国家航空航天局的官方网站是一个让数百万用户访问该主要机构提供的新闻、图片、视频和播客的地方。Django 开发了官方 NASA 网站的某些特定部分。
The National Aeronautics and Space Administration’s official website is a place for millions of users to visit and check out the news, images, videos and podcasts provided by the premiere agency. Django develops some specific parts of official NASA website.

The Washington Post
如果世界上有一家有影响力的报纸,那肯定就是《华盛顿邮报》。《华盛顿邮报》的网站是一个非常流行的在线新闻来源,可作为其日报的补充。《华盛顿邮报》的网站拥有巨大的浏览量和流量,而 Django Web 框架能够轻松地应对这些问题。
If there’s one influential newspaper in the world, it is certainly the Washington Post. The Washington Post’s website is a hugely popular online news source to accompany their daily paper. Its huge amount of views and traffic has been easily handled by Django web framework.

Reddit Gifts
大受欢迎的 Reddit 网站已经推出了一款名为 Reddit Gifts 的在线匿名礼物交换和聚会平台。该网站连接了来自世界各地的用户,并在他们之间促成礼物交换。Django Web 框架为其功能提供支持。
The massively popular Reddit website has launched an online, anonymous gift exchange and meetup platform called Reddit Gifts. The site connects users from around the world and facilitates gifts exchange between them. The Django web framework powers its functionalities.

Prezi
Prezi 是基于 Django 框架构建的 Microsoft PowerPoint 的云端替代产品。该网站提供了一个虚拟画布,可以对其进行操作、放大和缩小。这提供了整个演示文稿的视图,而不是各个幻灯片。
Prezi is a cloud based alternative to Microsoft PowerPoint built on the Django framework. The site provides a virtual canvas that can be manipulated and zoomed in and out. This provides the entire view of the presentation rather than individual slides.

Installing and Creating a Django project and app
在安装 Django 之前,我们必须确保已经安装了 Python。假设你正在使用 virtualenv,只需 pip install django 就足够了。
Before installing Django, we have to make sure that Python is installed. Assuming you are using virtualenv, a simple pip install django should suffice.
Creating Django Project
完成安装后,我们需要创建一个 Django 项目。
Once the installation is completed, we need to create a Django project.
在 Windows 机器中运行以下命令将创建如下所示的 Django 项目:
Running the below command in your windows machine will create the following django project −
django-admin startproject my_project_name
django-admin startproject my_project_name


键入 dir 将显示一个新的文件和一个新的目录,如上所示。
Typing dir will show one new file and one new directory as shown above.
manage.py −manage.py 是一个命令行可执行 Python 文件,它只是 django-admin 的包装器。它帮助我们管理项目,这也暗示在它的名称中。
manage.py − manage.py is a command-line-executable Python file which is just a wrapper around django-admin. It helps us manage our project which is implied in its name as well.
通过此,它在 myFirstDjangoProject 中创建了一个名为 myFirstDjangoProject 的目录,它表示我们项目的配置根目录。让我们深入探索一下。
With this, it created a directory called, myFirstDjangoProject inside myFirstDjangoProject which represents the configuration root for our project. Let us explore much deeper into it.
Configuring Django
通过将 myFirstDjangoProject 目录称为“配置根”,我们的意思是该目录包含为常规配置我们的 Django 项目而必需的文件。该目录外部的几乎所有内容都将仅关注与项目的模型、视图、路由等相关的“业务逻辑”。将项目连接在一起的所有点都会在此处生成。
By calling the myFirstDjangoProject directory “configuration root”, we mean this directory holds the files necessary for generally configuring our Django project. Pretty much everything outside this directory will be focused solely on the “business logic” associated with the project’s models, views, routes, etc. All points that connect the project together will lead here.

-
init.py − This is empty and changes the directory into an importable Python package.
-
settings.py − As the name suggest, it is the place where most configuration items will be set.
-
urls.py − The URLs are set with urls.py. With this, we don’t have to explicitly write every URL for the project in this file. However, we have to tell Django about where the URLs have been declared (i.e., we need to link other URL in urls.py).
-
Wsgi.py − This is to help application in production and is similar to other applications like Flask, Tornado, Pyramid which exposes some “app” object.
Setting the settings
查看 settings.py 将揭示它的大小相当大 - 这只是默认设置。其他我们需要注意的事情是静态文件、数据库、媒体文件、云集成或 Django 项目可以配置的其他几十种方式。让我们了解 settings.py 文件中提到的要点:
Taking a look inside settings.py will reveal its considerable size – and these are just the defaults. Other things that we need to take care are the static files, database, media files, cloud integration or other dozens of ways that a Django project can be configured. Let’s understand some points mentioned in the settings.py file −
-
BASE_DIR − This is helpful for locating files. Inside the setting.py file, BASE_DIR parameter sets the absolute path to the base directory.
-
SECRET_KEY − It is used for making hashes. In general, we used secret_key for cookies, sessions, csrf protection and auth tokens.
-
DEBUG − We can set it to project running either in development or production mode.
-
ALLOWED_HOSTS − We provide the list of hostnames through which our application is being served. In development mode, it is optional to set; however, in production machine, we need to set our Django project.
-
INSTALLED_APPS − It is the list of Django “apps” that are currently installed and running in our Django project. In-built Django provides six installed apps as follows −
-
MIDDLEWARE − It helps our Django project to run. It’s a python class that hooks into django request/response processing.
-
TEMPLATES − It defines how the document should be displayed in the frontend. Django templates are used for producing any text-based format.
-
WSGI_APPLICATION − Any server we set up has to know where the WSGI file is. In case you’re using an external server, it will look in its own settings. By default, it points to objects in wsgi.py.
-
DATABASES − It sets to the databases our Django project is currently accessing. It is mandatory to set default database. In case we set the database of our choice, we need to mention few things related to database like - HOST, USER, PASSWORD, PORT, database NAME, and appropriate ENGINE.
-
STATIC_URL − It is the URL to use when referring to static files located in STATIC_ROOT. By default, it’s None.
然而,我们可能需要为静态文件添加一个路径。转到文件末尾,在 STATIC_URL 条目的正下方,添加一个名为 STATIC_ROOT 的新条目,如下所示 −
However, we may need to add a path for static files. Go down to the end of the file, and just underneath the STATIC_URL entry, add a new one called STATIC_ROOT as shown below −
myFirstDjangoProject/settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
Setting up a Database
有很多不同的数据库软件可以存储你网站的数据。我们将使用默认软件 sqlite3。
There’s a lot of different database software that can store date for your site. We’ll use the default one, sqlite3.
这是在你 myFirstDjangoProject/settings.py − 中给出的以下部分中已经设置的
This is already set up in the below given part of your myFirstDjangoProject/settings.py −
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
为了为我们的博客创建一个数据库,让我们在控制台中运行以下代码 − python manage.py migrate (我们需要在包含 manage.py 文件的 myFirstDjangoProject 目录中。
To create a database for our blog, let’s run the following in the console − python manage.py migrate (we need to be in the myFirstDjangoProject directory that contains the manage.py file.
如果一切顺利,你将获得以下输出 −
You will get the following output if everything goes well −

Starting the Web Server
你需要在包含 manage.py 文件的目录中。在控制台中,我们可以通过如下所示运行 python manage.py runserver 来启动 Web 服务器 −
You need to be in the directory that contains the manage.py file. In the console, we can start the web server by running python manage.py runserver as follows −

现在,你需要做的就是检查你的网站是否正在运行。打开你的浏览器(Firefox、Chrome、Safari、Internet Explorer 或你用任何其他浏览器)并输入此地址 −
Now all you need to do is check that your website is running. Open your browser (Firefox, Chrome, Safari, Internet Explorer or whatever you use) and enter this address −
或
or
http://localhost:8000/ # 因为我们的 Web 服务器仅在我们的本地计算机中运行。
http://localhost:8000/ # As our webserver is running in our local machine only.
恭喜!您刚刚创建了你的第一个网站并使用 Web 服务器运行它!
Congratulations! You’ve just created your first website and run it using a web server!

在 Web 服务器运行期间,你不会看到一个新的命令行提示来输入其他命令。终端将接受下一项文本,但不会执行新命令。这是因为 Web 服务器持续运行以侦听传入请求。
While the web server is running, you won’t see a new command-line prompt to enter additional commands. The terminal will accept next text but will not execute new commands. This is because the web server continuously runs in order to listen to incoming requests.
Django Models
我们正在尝试创建一个 Django 模型,它将存储我们博客中的所有帖子。但要确保其正常工作,我们需要了解对象。
We are trying to create a Django model that will store all the posts in our blog. But to make sure it works, we need to learn about objects.
Objects
对象是属性和操作的集合。让我们用一个例子来理解这一点。假设我们想模拟一只猫,我们将创建一个名为 Cat 的对象,它具有颜色、年龄、情绪(好/坏/困)和主人等属性。
Objects is a collection of properties and actions. Let us understand this with an example. Suppose we want to model a cat, we will create an object called Cat that has properties such as color, age, mood (good/bad/sleepy) and owner.
然后,Cat 有一些动作:呼噜、抓挠或喂食。
Then the Cat has some actions: purr, scratch or feed.
Cat
--------
color
age
mood
owner
purr()
scratch()
feed(cat_food)
CatFood
--------
taste
因此,我们基本上试图用属性(称为对象属性)和操作(称为方法)在代码中描述真实的事物。
So basically we are trying to describe real things in code with properties (called object properties) and actions (called methods).
在构建博客时,我们需要一些文本内容和标题。有作者姓名、创建日期和发布日期也是必要的。
As we are building a blog, we need some text content and a title. It is also necessary to have the author’s name, date of creation and also the date of publication.
因此,我们的博客将包含以下对象:
So our blog will have the following objects −
Post
--------
title
text
author
created_date
published_date
我们还需要一些用于发布该帖子的方法。在了解了什么是对象之后,我们可以为博客文章创建一个 Django 模型。
Also we need to have some method that publishes that post. As we are now aware of what an object is, we can create a Django model for our blog post.
模型是 Django 中一种特殊的对象类型,并保存到数据库中。我们将在 SQLite 数据库中存储我们的数据。
A model is a special kind of object in Django and is saved in the database. We will store our data in SQLite database.
Creating an application
为了保持清晰明了,我们将在项目中创建一个单独的应用程序。接下来,我们将尝试通过运行以下简单的命令来创建博客 Web 应用程序。
To keep everything clear, we will create a separate application inside our project. Below, we’ll try to create a blog web application by running below mentioned simple command.
现在我们注意到,一个新的 myBlog 目录已创建并且其中包含多个文件。我们项目中的目录和文件应如下所示:
Now we will notice that a new myBlog directory is created and it contains a number of files now. The directories and files in our project should be as following −

创建应用程序后,我们还需要告诉 Django 使用它。我们在文件 myFirstDjangoProject/settings.py 中执行此操作。
After creating an application, we also need to tell Django to use it. We do that in the file myFirstDjangoProject/settings.py.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myBlog',
]
Creating a blog post model
在 myBlog/models.py 文件中,我们定义了所有称为模型的对象——这是一个我们定义博客文章的地方。
In the myBlog/models.py file, we define all objects called Models – this is a place in which we will define our blog post.
打开 myBlog/models.py,删除其中的所有内容,并按如下所示编写代码:
Let’s open myBlog/models.py, remove everything from it, and write code as follows −

首先,我们通过调用 from 或 import 从其他文件中导入一些功能。这样,我们可以通过 from and import 包含一些部分,而不用在每个文件中复制和粘贴相同内容。
Firstly, we import some functionalities from other files by calling from or import. So with this, instead of copying and pasting the same things in every file, we can include some parts with from and import.
class Post(models.Model) - 这行代码定义了我们的模型(它是一个对象)。
class Post(models.Model) − This line defines our model (it is an object).
-
class is a special keyword that indicates that we are defining an object.
-
Post is the name of our model. Always start a class name with an uppercase letter.
-
models.Model means that the Post is a Django Model, so Django knows that it should be saved in the database.
现在,让我们讨论一下上面定义的属性:title、text、created_date、published_date 和 author。为此,我们需要定义每个字段的类型。
Now let us discuss about the properties we defined above: title, text, created_date, published_date and author. To do that, we need to define the type of each field.
-
models.CharField − This is how you define text with a limited number of characters.
-
Models.TextField − This is for long text without a limit.
-
Models.DateTimeField − This is for date and time.
-
Models.ForeignKey − This is a link to another model.
我们使用 def 来定义函数/方法,而 str 是该方法的名称。
We define a function/method with def and publish is the name of the method.
方法通常会返回一些内容。在本文中,当我们调用 str () 时,我们会得到一篇 Post 标题下的文本 (字符串)。
Methods often return something. Here when we call str(), we will get a text (string) with a Post title.
Creating tables for models in your database
最后一步是向数据库添加一个新模型。首先,我们必须让 Django 明白我们已对模型做出一些更改。让我们在控制台窗口中使用命令 python manage.py make migrations myBlog 进行此操作,如下所示:-
The final step is to add a new model to our database. First, we have to let Django understand that we have made some changes in our model. Let us do the same in our console window with command python manage.py make migrations myBlog as shown below −

然后,Django 会准备一个迁移文件,我们现在必须将其应用于数据库。在控制台中,我们可以输入: python manage.py migrate myBlog ,输出应如下所示:-
Then, Django prepares a migration file that we now have to apply to our database. In our console we can type: python manage.py migrate myBlog and the output should be as follows −

我们的 Post 模型现在已在我们的数据库中。
Our Post model is now in our database.
Django Admin
我们要添加、编辑和删除刚建模的帖子,现在我们要使用 Django 管理。
To add, edit and delete the posts we’ve just modelled, we are using Django admin.
所以,让我们打开 myBlog/admin.py file 并把以下内容放入其中 -
So let us open the myBlog/admin.py file and put below contents in this −

首先,我们要导入(包含)在之前的章节中定义的 Post 模型。为了让我们的模型在管理页面中可见,我们需要使用 manage.py createsuperuser (Post)向 admin.site 注册模型。
Firstly, we import (include) the Post model defined in the previous chapter. To make our model visible on the admin page, we need to register the model with admin.site.register (Post).
要登录管理网站,你需要创建一个超级用户帐户,这个帐户可以控制网站上的所有内容。所以,请停止 Web 服务器并在命令行中输入 manage.py createsuperuser ,然后按 Enter。
To login to an admin site, you need to create a superuser – a user account that has control over everything on the site. So stop the webserver and type in command line python manage.py createsuperuser, and press enter.

好,现在是时候看一下我们的 Post 模型了。记住在控制台中运行 python manage.py run server 来运行 Web 服务器。转到浏览器并输入地址 https://127.0.0.1:8000/admin/. ,使用我们刚刚选择的凭据登录。然后,你应看到与以下类似的 Django 管理信息中心:-
Ok, so it’s time to look at our Post model. Remember to run python manage.py run server in console to run the web server. Go to your browser and type the address https://127.0.0.1:8000/admin/. Log in with the credentials we have just chosen. Then you should see the Django admin dashboard as below −

转到 Post 并使用它进行一些尝试。你可以从任何地方添加许多博文和内容。你的博文会看起来像这样:-
Go to Posts and experiment a little with it. You can add many blog posts, and contents from anywhere. Your blog will look something like this −

本课程只是 Django 的概览,我们能够使用几行代码创建一个博文。
This is just an overview of Django and we are able to create a blog with just a few lines of code.