Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs/intro/tutorial03.txt #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/intro/tutorial03.txt
Original file line number Diff line number Diff line change
@@ -48,6 +48,9 @@ The first step of writing views is to design your URL structure. You do this by
creating a Python module, called a URLconf. URLconfs are how Django associates
a given URL with given Python code.

第一步是设计URL结构。首先创建Python模块,并命名为URLconf。Django通过URLconf连接
和给定的URL和Python代码。

When a user requests a Django-powered page, the system looks at the
:setting:`ROOT_URLCONF` setting, which contains a string in Python dotted
syntax. Django loads that module and looks for a module-level variable called
@@ -59,6 +62,15 @@ Django starts at the first regular expression and makes its way down the list,
comparing the requested URL against each regular expression until it finds one
that matches.

当用户获取一个Django页面,系统会查询 :setting:`ROOT_URLCONF`环境。`ROOT_URLCONF`含有
Python语法中的字符串。Django载入指定模版并定位名为``urlpatterns``的变量。
``urlpatterns``格式如下::

(regular expression, Python callback function [, optional dictionary])

Django从第一个表达式开始读取整个list,比较requested URL和list中的每个表达式,
直到找到符合的配对。

When it finds a match, Django calls the Python callback function, with an
:class:`~django.http.HttpRequest` object as the first argument, any "captured"
values from the regular expression as keyword arguments, and, optionally,