Django Views and URLconfs

碧玉妆成一树高,万条垂下绿丝绦。 不知细叶谁裁出,二月春风似剪刀。

    

原文尽在:http://djangobook.com/ 转载请注明出处:http://www.cnblogs.com/A-FM/p/6721382.html

Django Views and URLconfs(Django的视图和URL配置)

In the previous chapter, I explained how to set up a Django project and run the Django development server. In this chapter, you’ll learn the basics of creating dynamic Web pages with Django.(在前面的章节,我解释了怎样去创建一个Django工程和运行Django开发服务器,在这一节,在这一节你会学到创建Django的Web页面的基本语法。)

Your First Django-Powered Page: Hello World(你的第一个Django:Hello World)

As our first goal, let’s create a Web page that outputs that famous example message: “Hello world.” If you were publishing a simple “Hello world” Web page without a Web framework, you’d simply type “Hello world” into a text file, call it “hello.html", and upload it to a directory on a Web server somewhere. Notice in that process you’ve specified two key pieces of information about that Web page: its contents (the string "Hello world") and its URL (e.g. http://www.example.com/hello.html). With Django, you specify those same two things, but in a different way. The contents of the page are produced by a view function, and the URL is specified in a URLconf. First, let’s write our “Hello world” view function.(作为我们的第一个目标,让我们创建一个Web page 输出著名的信息“Hello World”,如果你已经做过一个简单的“Hello World” Web page 并且没有使用Web框架,你应该只是简单的把“Hello world”输入你的文本文件,命名为“hello.html”,并且上传他到任何一个Web 服务器的目录,注意在这个工程中你已经制定两个关键的信息关于这个Web page :他包括这个字符串“Hello World”,and他的url 例如http://www.example.com/hello.html,用Django的话你会指定这两个相同的事情,但是是用不同的方法,他会包括这个页面在视图函数,and 这个URL在URL配置中制定,让我们写一个自己的“Hello World”视图函数吧!

Your First View(你的第一份视图)

Within the mysite directory that we created in the last chapter, create an empty file called views.py. This Python module will contain our views for this chapter. Our “Hello world” view is simple. Here’s the entire function, plus import statements, which you should type into the views.py file:( 在我们的mysite目录里面就是我们上一节最后创建的那个,创建一个空目录命名为views.py。Python的模块将会包含我们这一节的视图。我们的“Hello World”是非常简单的。这里是完整的函数和import 状态,你需要将他输入到views.py里面。)

from django.http import HttpResponse  

def hello(request):
    return HttpResponse("Hello world")

Let’s step through this code one line at a time:(现在让我们一步步的分析这个代码)

  • First, we import the class HttpResponse, which lives in the django.http module. We need to import this class because it’s used later in our code.(首先我们import了 这个HttpResponse累,他就在django.http 模块里面我们需要import这个模块因为我们一会会用到它。)
  • Next, we define a function called hello– the view function.(然后我们定义了一个名为hello 的视图函数。)
  • Each view function takes at least one parameter, called request by convention. This is an object that contains information about the current Web request that has triggered this view, and is an instance of the class django.http.HttpRequest.(每个视图至少要有一个参数,习惯上称为request。这个对象包含了当前Web request信息,这是一个触发试图,他是django.http.HttpRequest的一个实例函数----其实这个我翻译不清楚)

In this example, we don’t do anything with request, but it must be the first parameter of the view nonetheless. Note that the name of the view function doesn’t matter; it doesn’t have to be named in a certain way in order for Django to recognize it. We’re calling it hello here, because that name clearly indicates the gist of the view, but it could just as well be named hello_wonderful_beautiful_world, or something equally revolting. The next section, “Your First URLconf”, will shed light on how Django finds this function.(在这个例子里面,我们对request什么都没做,但是他必须是第一个参数在这个视图里面,注意这个视图函数的名字是不重要的,他不需要特意的以某种方式命名才能让Django识别他。我们在这里称他为 hello 因为这个名字清楚的表明这个函数主旨,当然他也可以被命名为 hello_wonderful_beautiful_world ,或者是同样令人讨厌的其他名字,下一部分“你的第一个URL配置” 将会告诉你如何让django 发现这个函数。   shed light 不会翻译。。)。

The function is a simple one-liner: it merely returns an HttpResponse object that has been instantiated with the text "Hello world".(这个函数只有简单的一行:他仅仅返回了一个用“Hello World”实例化的一个HttpResponse 对象)

The main lesson here is this: a view is just a Python function that takes an HttpRequest as its first parameter and returns an instance of HttpResponse. In order for a Python function to be a Django view, it must do these two things. (There are exceptions, but we’ll get to those later.) (在这里最重要的一课是:一个视图就是一个Python函数,他接收一个HttpRequest作为第一个参数,并且返回一个HttpResponse的实例化对象。为了让一个Python function函数成为一个 django view 他必须做这两件事情,他又例外,但是我们会在以后去接触它。)

Your First URLconf(你的第一个URL配置)

If, at this point, you ran python manage.py runserver again, you’d still see the “Welcome to Django” message, with no trace of our “Hello world” view anywhere. That’s because our mysite
project doesn’t yet know about the hello view; we need to tell Django explicitly that we’re activating this view at a particular URL. Continuing our previous analogy of publishing static HTML files, at this point we’ve created the HTML file but haven’t uploaded it to a directory on the server yet.(如果现在你运行python manage.py runserver,你应该会依然看到 “Welcome to Django”信息, 没有一点我们“hello world”的踪迹,这是因为我们的mysite工程还是不知道关于 hello 试图的信息;我们需要明确的告诉告诉 Django 我们声明了这个URL,继续类别我们以前的静态HTML 文件,现在我们创建了这个HTMl 文件但是我们没有 上传他到服务器目录中。---意思就是和以前的笨方法类比的话我们还缺一步

To hook a view function to a particular URL with Django, we use a URLconf. A URLconf is like a table of contents for your Django-powered Web site. Basically, it’s a mapping between URLs and the view functions that should be called for those URLs. It’s how you tell Django, “For this URL, call this code, and for that URL, call that code. (为了将这个视图函数的URL和Django 挂钩,我们需要用URL 配置。)

For example, when somebody visits the URL /foo/, call the view function foo_view(), which lives in the Python module views.py. When you executed django-admin startproject in the previous chapter, the script created a URLconf for you automatically: the file urls.py.(例如当某人访问 URL /foo/,称这个 视图函数为foo_view(),他就在Python的 views.py 模块里面。在上一节我们执行 django-admin startproject 的时候,该脚本自动为你创建了一个URL 配置:urls.py)

By default, it looks something like this: (一般来说,他也就长的这个吊样。)

"""mysite URL Configuration

The urlpatterns list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Add an import:  from blog import urls as blog_urls
    2. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

 

If we ignore the documentation comments at the top of the file, here’s the essence of a URLconf:  (如果我们不看文件最上面的 文档说明的话,这里就是URL配置文件的本质。)

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
]

 

Let’s step through this code one line at a time:(现在让我们一步步的分析这些代码)

  • The first line imports two functions from the django.conf.urls module: include which allows you to include a full Python import path to another URLconf module, and url which uses a regular expression to pattern match the URL in your browser to a module in your Django project.(第一行导入了两个函数 从 django.conf.urls模块:include他允许你include一个完整的python import 路径到另一个 URL 配置模块,and url 用正则表达式去匹配你的浏览器请求在你的Django 工程里面)
  • The second line calls the function admin from the django.contrib module. This function is called by the include function to load the URLs for the Django admin site.(第二行 叫做admin的函数从django.contrib模块导入,这个函数被include 导入到url中,用于Django的管理员站点。)
  • The third line is urlpatterns – a simple list of url() instances.(第三行urlpatterns 一个简单的url 列表实例化)

The main thing to note here is the variable urlpatterns, which Django expects to find in your URLconf module. This variable defines the mapping between URLs and the code that handles those URLs. To add a URL and view to the URLconf, just add a mapping between a URL pattern and the view function. Here’s how to hook in our hello view:(这里最重要的东西就是urlpatterns 这个变量,哪里有Django中你期望发现的URL配置模块,这个变量用url和正则表达式代码写成map的格式去处理url、如果要添加url 视图,只需要添加一个map视图用URL正则表达式的方法,这里是如何添加我们hello的实例。)

from django.conf.urls import include, url
from django.contrib import admin
from mysite.views import hello  
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^hello/$', hello),
]

 

We made two changes here:(我们在这里做出来两处改变)

  • First, we imported the hello view from its module – mysite/views.py, which translates into mysite.views in Python import syntax. (This assumes mysite/views.py is on your Python path.)(首先我们导入了hello视图函数从 mysite/views.py 里面,他在Python的语法里面被翻译成mysite.views,(这里嘉定mysite/views.py是你的Python路径))
  • Next, we added the line url(r'^hello/$', hello), to urlpatterns. This line is referred to as a URLpattern. The url() function tells Django how to handle the url that you are configuring. The first argument is a pattern-matching string (a regular expression; more on this in a bit) and the second argument is the view function to use for that pattern. url() can take other optional arguments as well, which we’ll cover in more depth in Chapter 7.(接下来,我么添加了一行url(r'^hello/$', hello),urlpatterns. 这一行被添加作为URLpattern,url()函数告诉Django如何处理这个url用你的配置。第一个参数是正则表达式字符串,and第二个参数是视图函数用于模型---实在翻译不懂。。url()也可以用其他可选的参数,我们将在第七节深入讲解。)

One more important detail we’ve introduced here is that ‘r’ character in front of the regular expression string. This tells Python that the string is a “raw string” – its contents should not interpret backslashes.(一个很重要的细节我们要在这里进行讲解,就是在正则表达式前面的“r”字符,他告诉Python这个字符串是“未加工字符串”,他的内容不应该解释反斜杠)

In normal Python strings, backslashes are used for escaping special characters – such as in the string “\n”, which is a one-character string containing a newline. When you add the r to make it a raw string, Python does not apply its backslash escaping – so, “r'\n'” is a two-character string containing a literal backslash and a lowercase “n”. (一般来说Python的字符串反斜杠用于解释一些特殊的字符,例如“\n”,这是 一个字符 -回车 。当你添加r 让他成为 未加工的字符串的时候,Python不会用反斜杠去进行转义,因此 r“\n” 是两个字符串也就是字面上的意思,包含一个反斜杠和一个字符“n”)

There’s a natural collision between Python’s usage of backslashes and the backslashes that are found in regular expressions, so it’s best practice to use raw strings any time you’re defining a regular expression in Django.(这是自然的反斜杠在Python之中的用法,所以最好在练习的时候就用原始字符串,当你在Django中定义正则表达式的时候。)

In a nutshell, we just told Django that any request to the URL /hello/ should be handled by the hello view function.(简而言之,我们仅仅告诉Django所有的/hello/一类的URL请求 都让hello函数去完成)

It’s worth discussing the syntax of this URLpattern, as it may not be immediately obvious. Although we want to match the URL /hello/, the pattern looks a bit different than that. Here’s why:(讨论一下URLpattern的语法是非常有意义的,因为他不是显而易见的,尽管我们希望匹配到URL /hello/ ,但是这个公式看上去有那么一点点的差别,下面是为什么。)

  • Django removes the slash from the front of every incoming URL before it checks the URLpatterns. This means that our URLpattern doesn’t include the leading slash in /hello/.
    At first, this may seem unintuitive, but this requirement simplifies things – such as the inclusion of URLconfs within other URLconfs, which we’ll cover in Chapter 7.(Django移除了每个URL前面的斜杠当检查URLpattern的时候,这意味着我们的URLpattern不包括开头的斜杠在/hello/前面。这样看起来可能会不是很直观,但是这样的要求简化了许多事情---例如URL模式内嵌,我们将会在第七节详细讲解。)
  • The pattern includes a caret (^) and a dollar sign ($). These are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,”
    and the dollar sign means “require that the pattern matches the end of the string.” (模式包含了一个脱字符和一个dollar符,这些都是正字表达式字符,他们有特殊的意义:脱字符表示 从表达式头部开始匹配,dollar表示这是匹配的结尾)

This concept is best explained by example.(这个概念最好用例子来解释)
If we had instead used the pattern ^hello/ (without a dollar sign at the end), then any URL starting with /hello/ would match, such as /hello/foo and /hello/bar, not just /hello/.Similarly, if we had left off the initial caret character (i.e., hello/$), Django would match any URL that ends with hello/, (如果我们用这一种^hello/模式的话 (结尾没有dollar 符号),所有以 /hello/开头的字符串都会被匹配到 --- 例如 /hello/foo and /hello/bar,不仅仅只有/hello/。同样的,如果左边没有脱字符 例如 hello/$,Django将会匹配任何以hello/结尾的网址。
such as /foo/bar/hello/.If we had simply used hello/, without a caret or dollar sign, then any URL containing hello/ would match, such as /foo/hello/bar.Thus, we use both the caret and dollar sign to ensure that only the URL /hello/ matches – nothing more, nothing less. Most of your URLpatterns will start with carets and end with dollar signs, but it’s nice to have the flexibility to perform more sophisticated matches.(例如/foo/bar/hello/,如果我们简单的用hello/ 没有脱字符和dollar符号,然后只要URL中包含 /hello的话就会被匹配,例如/foo/hello/bar 。因此我们同时使用 脱字符和dollar符 用以确定不多不少只匹配/hello/。你的大部分URLpattern都会以脱字符开始,dollar结束,但是他会很漂亮的处理复杂的匹配式)

You may be wondering what happens if someone requests the URL /hello (that is, without a trailing slash). Because our URLpattern requires a trailing slash, that URL would not match. However, by default, any request to a URL that doesn’t match a URLpattern and doesn’t end with a slash will be redirected to the same URL with a trailing slash (This is regulated by the APPEND_SLASH Django setting, which is covered in Appendix D).(你可能会觉得疑惑如果某一个request是 /hello 没有斜杠结尾的话 会发生什么?因为我们的URLpattern 需要 以斜杠结尾,所以这话个URL无法匹配,然而,默认情况下对尾部没有斜杠的任何URL将会重定向带相同的带有斜杠的URL那里。这个规则是被Django的setting 文件中的APPEND_SLASH 决定的不喜欢的话可以自己更改。) 

The other thing to note about this URLconf is that we’ve passed the hello view function as an object without calling the function. This is a key feature of Python (and other dynamic languages): functions are first-class objects, which means you can pass them around just like any other variables. Cool stuff, eh?(另外需要注意的事情是关于URLconf,我们将hello 函数作为对象传递 而不是作为函数进行调用。这是Python很关键的特色(和其他动态语言的),函数是一级对象,也就是说你可以传递他们就像传递其他变量那样。酷吧?)

To test our changes to the URLconf, start the Django development server, as you did in Chapter 1, by running the command python manage.py runserver. (If you left it running, that’s fine, too. The development server automatically detects changes to your Python code and reloads as necessary, so you don’t have to restart the server between changes.) The server is running at the address http://127.0.0.1:8000/, so open up a Web browser and go to http://127.0.0.1:8000/hello/. You should see the text “Hello world” – the output of your Django view (Figure 2-1).,(为了测试我们对URLconf的改变,现在开始运行Django开发服务器,正如你在第一节所做的那样运行这个命令 :python manage.py runserver 如果运行成功的话,那就很好,开发服务器会自动检查你的Python代码改变,有需要的话会自动重启开发服务器,所以你不需要自己重启开发服务器在做出改变之后,服务运行在 http://127.0.0.1:8000/  所以打开你的浏览器进入http://127.0.0.1:8000/hello/ 你应该会看到 “Hello World” - 由你的Django视图输出的文本。)

Figure 2-1: Hooray! Your first Django view. (万岁,你第一个Django视图)

Regular Expressions (正则表达式)

Regular expressions (or regexes) are a compact way of specifying patterns in text. While Django URLconfs allow arbitrary regexes for powerful URL matching, you’ll probably only use a few regex symbols in practice. Table 2-1 lists a selection of common symbols.(正则表达式是紧凑的文本指定模式,Django允许任何正则表达式去做强有力的URL 匹配,你可能只会用很少的正则表达式符号去实践,表2-1是一些常见的正则表达式符号。)

Table 2-1: Common regex symbols

SymbolMatches
. (dot) Any single character 任何单一 的字符
\d Any single digit  任何单一的 数字
[A-Z] Any character between A and Z (uppercase)   在A-Z之间任何一个字符(大写的)
[a-z] Any character between a and z (lowercase)    在a-z之间任何一个字符(小写的)
[A-Za-z] Any character between a and z (case-insensitive) 任何一个英文字母,不区分大小写
+ One or more of the previous expression (e.g., \d+ matches one or more digits) 一个或者多个前面的表达 (例如 \d+ 表达匹配一个或者多个数字)
[^/]+ One or more characters until (and not including) a forward slash    一个或者多个不为 /的字符
? Zero or one of the previous expression (e.g., \d? matches zero or one digits)  一个或者零个 前面的字符
* Zero or more of the previous expression (e.g., \d* matches zero, one or more than one digit)  没有或者多个前面的字符
{1,3} Between one and three (inclusive) of the previous expression (e.g., \d{1,3} matches one, two or three digits) 1-3 之间个前面的字符。

For more on regular expressions, see the Python regex documentation.

A Quick Note About 404 Errors  (404错误的快速参考)

At this point, our URLconf defines only a single URLpattern: the one that handles requests to the URL /hello/. What happens when you request a different URL? To find out, try running the Django development server and visiting a page such as http://127.0.0.1:8000/goodbye/. You should see a “Page not found” message (Figure 2-2). Django displays this message because you requested a URL that’s not defined in your URLconf.(这时候我们的URLconf近定义一个URLpattern:一个处理hello请求的函数,当我们访问一个没有定义的URL的时候会发生什么呢?为了解决这个问题,我们运行开发服务器并且访问一个网址例如:http://127.0.0.1:8000/goodbye/. 你应该会看到“page not found” 信息 (图中的2-2)Django展示这个信息因为您并没有在视图函数中定义这个URLconf)

Django Views and URLconfs - Django's 404 pageFigure 2-2: Django’s 404 page

The utility of this page goes beyond the basic 404 error message. It also tells you precisely which URLconf Django used and every pattern in that URLconf. From that information, you should be able to tell why the requested URL threw a 404.(这个页面实际上已经超过了普通的404错误信息(给你很多可以Debug的信息),他精确的告诉了你Django的每一个URLconf 的信息。从信息中可以知道,你应该已经知道了为什么他会抛出404错误信息)

Naturally, this is sensitive information intended only for you, the Web developer. If this were a production site deployed live on the Internet, you wouldn’t want to expose that information to the public. For that reason, this “Page not found” page is only displayed if your Django project is in debug mode.(当然,这个敏感的信息只应该展现给你,作为Web的开发者,如果要将这个站点放到因特网上,你一定不想暴露出这个信息给大众,这个“Page not found”页面,只在Django工程Debug的时候在展现出来)

I’ll explain how to deactivate debug mode later. For now, just know that every Django project is in debug mode when you first create it, and if the project is not in debug mode, Django outputs a different 404 response.(我一会会解释如何禁用这个Debug模式,现在只需要知道每一个新建的Django peoject 都时在Debug模式下面的。and 如果该peoject不再Dubug模式下面,Django会输出一个不一样的404响应)

A Quick Note About the Site Root(网站根目录相关快速查询手册)

As explained in the last section, you’ll see a 404 error message if you view the site root – http://127.0.0.1:8000/. Django doesn’t magically add anything to the site root; that URL is not special-cased in any way.(正如在文章结尾处看到的一样,你会看到404错误信息,如果你访问网站根目录 – http://127.0.0.1:8000/. Django不会添加任何信息到网站根目录,URL任何时候不会出处于特殊情况。)

It’s up to you to assign it to a URLpattern, just like every other entry in your URLconf. The URLpattern to match the site root is a bit unintuitive, though, so it’s worth mentioning.(这完全取决于你,就像其他的网站URL入口一样,这个用于匹配网站根目录的URLpattern有一点点的不直观因此我们有必要去考虑一下它)

When you’re ready to implement a view for the site root, use the URLpattern “^$”,(当你准备实现一个网站根目录的视图的时候,就用这个URLpattern ---- “^$”)
which matches an empty string. For example:(他将匹配所有的空字符串,例如:)

from mysite.views import hello, my_homepage_view

urlpatterns = [
    url(r'^$', my_homepage_view),
    # ...

 

How Django Processes a Request (Django 是如何处理一个请求的呢?)

Before continuing to our second view function, let’s pause to learn a little more about how Django works. Specifically, when you view your “Hello world” message by visiting http://127.0.0.1:8000/hello/ in your Web browser, what does Django do behind the scenes? It all starts with the settings file.(在我们开始我们第二个视图函数之前,让我们暂停一下去学习一点关于Django的工作流程。具体地说,当你通过浏览器访问http://127.0.0.1:8000/hello/看你的“Hello world”信息的时候,Django在后台做了些什么呢?----所有的一切都开始于那个setting file)

When you run python manage.py runserver, the script looks for a file called settings.py in the inner mysite directory. This file contains all sorts of configuration for this particular Django project,(当你运行python manage.py runserver的时候,Django会去mysite 目录里面寻找一个叫做setting.py 的文件,这个文件包含了各种各样的Django配置信息。)
all in uppercase: TEMPLATE_DIRS, DATABASES, etc. The most important setting is called ROOT_URLCONF. ROOT_URLCONF tells Django which Python module should be used as the URLconf for this Web site.(都是大写的: TEMPLATE_DIRS, DATABASES, etc.最重要的设置被称为ROOT_URLCONF,他告诉Django那个Python的模块应该被用作URLconf作为她的Web站点)

Remember when django-admin startproject created the files settings.py and urls.py? The auto-generated settings.py contains a ROOT_URLCONF setting that points to the auto-generated urls.py.
Open the settings.py file and see for yourself; it should look like this: (还记得当我们创建工程的时候,自动生成的文件s settings.py and urls.py么? 这个自动生成的settings.py 包含ROOT_URLCONF用于指向自动生成的urls.py)

ROOT_URLCONF = 'mysite.urls'

 

This corresponds to the file mysite/urls.py. When a request comes in for a particular URL – say, a request for /hello/ – Django loads the URLconf pointed to by the ROOT_URLCONF setting. Then it checks each of the URLpatterns in that URLconf, in order, comparing the requested URL with the patterns one at a time, until it finds one that matches.(对应的文件是 mysite/urls.py,当请求进入一个特定的URL - 例如,一个对/hello/的请求,Django找到setting中的ROOT_URLCONF指向的文件,然后检查每个文件中的URLpattern,将其中的URL和request URL对比,知道发现一个匹配的。

When it finds one that matches, it calls the view function associated with that pattern, passing it an HttpRequest object as the first parameter. (We’ll cover the specifics of HttpRequest later.) As we saw in our first view example, a view function must return an HttpResponse. (当找到匹配的是开始调用相对应的 视图函数将HttpRequest作为第一个对象(我们稍后详细讲解HttpRequest)正如我们第一次看到的视图函数,一个试图函数必须返回一个HttpResponse。)

Once it does this, Django does the rest, converting the Python object to a proper Web response with the appropriate HTTP headers and body (i.e., the content of the Web page). In summary:(一旦这样,Django就可以休息了,然后转换Python对象到适当的Web response(一个Web页面)总而言之。)

  1. A request comes in to /hello/. (请求进入转入 /hello/)
  2. Django determines the root URLconf by looking at the ROOT_URLCONF setting. (Django 通过ROOT_URLCONF设置来确定 根URLconf)
  3. Django looks at all of the URLpatterns in the URLconf for the first one that matches /hello/. (Django 在所有的 URLpattern中寻找第一个和 /hello/ 匹配的URLconf)
  4. If it finds a match, it calls the associated view function. (如果发现了匹配的URLconf,就调用对应的视图函数)
  5. The view function returns an HttpResponse. (视图函数返回一个 HttpResponse)
  6. Django converts the HttpResponse to the proper HTTP response, which results in a Web page. (Django 转化HttpResponse 到 Http response,也就是一个网页的页面)

You now know the basics of how to make Django-powered pages. It’s quite simple, really – just write view functions and map them to URLs via URLconfs. (你现在应该知道怎样去用Django 做一个基本的页面了,他很简单,只需要写视图函数和 URLs 并通过 URLconfs 将其 map)

 

posted @ 2017-04-17 09:33  X-POWER  阅读(337)  评论(0编辑  收藏  举报