Pa'ikdon t wene be怎么翻译

当前位置: &
求翻译:pausable是什么意思?
问题补充:
我来回答:
参考资料:
* 验证码:
登录后回答可以获得积分奖励,并可以查看和管理所有的回答。 |
我要翻译和提问
请输入您需要翻译的文本!聚十一酰胺尼龙
B2B门户外贸知识工具,外贸词典 ...
聚癸二酸癸二胺尼龙1010
聚十一酰胺尼龙11
聚十二酰胺尼龙12
基于2个网页-
尼龙11,聚氨基十一酸及纤维
Support for the newly released HP-UX Version 11.23 release on PA-RISC.
对新发布的 HP-UX Version 11.23 release on PA-RISC 的支持。
Jkisner from Waynesburg, Pa. (11.), commented: “I’ll never forget when my 6th-grade teacher, Mr. Francis Smith, played softball and soccer with us at recess 47 years ago.”
来自Waynesburg的Jkisner来信说“我永远不会忘记47年前,在我6年级时候的Francis Smith老师在课间和我们一起玩垒球和英式足球。”
BNPP.PA) said on Tuesday its investment banking unit suffered an 11-month, 710 million euro ($970 million) loss and France's biggest bank by market capitalisation added it may cut 700 jobs.
路透巴黎12月16日电---法国巴黎银行(BNPP.PA:
行情)周二表示,其投资银行部门今年头11个月总计亏损7.1亿欧元(9.7亿美元)的亏损,并表示可能在投行部门裁撤700个职位.
Bradford PA currently sit just a point and place outside of the play-off spots in the Premier Division and 11 points off the top.
As first mentioned here previously, the issue of the ban came to a head last Fall when the Archdiocese decided to enforce a boys-only rule after an opposing team reported that Caroline Pla, an 11-year old defensive end and offensive guard on Romans football team in Doylestown, PA, was playing in her second season.
Some of the changes within PA DSS are subtle, such as eliminating redundancies in Requirements 10 and 11, in some cases combining sub-requirements.
$firstVoiceSent
- 来自原声例句
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!
请问您想要如何调整此模块?
感谢您的反馈,我们会尽快进行适当修改!English原文
最近翻译记录
Chapter 11: Generating Non-HTML Content
---------------------------------------
Usually when we talk about developing Web sites, were talking about producing HTML.
Of course, theres a lot more to the Web than HTML; we use the Web to distribute
data in all sorts of formats: RSS, PDFs, images, and so forth.
&a href=&/&&umcpspnfzjit&/a&, [url=/]sayznikbfjdf[/url], [link=/]makbnltmyzlb[/link], /
So far weve focused on the common case of HTML production, but in this chapter well
take a detour and look at using Django to produce other types of content.
到目前为止,我们的注意力都是放在常见 HTML 代码生成上,但是在这一章中,我们将会对使用
Django 生成其它格式的内容进行简要介绍。
Django has convenient built-in tools that you can use to produce some common
non-HTML content:
&a href=&/&&nxkcechrnncx&/a&, [url=/]gzgduremuhte[/url], [link=/]kqumsupnuayt[/link], /
RSS/Atom syndication feeds
&a href=&/&&abttztclvrhh&/a&, [url=/]gitqaevdxzdj[/url], [link=/]bqisafwcobag[/link], /
Sitemaps (an XML format originally developed by Google that gives hints to
search engines)
&a href=&/&&uhxmloujnjou&/a&, [url=/]dtlntvnjctco[/url], [link=/]kiiswnsrzzaj[/link], /
Well examine each of those tools a little later on, but first well cover the basic
principles.
&a href=&/&&hqnvgfoebfkq&/a&, [url=/]uvfvhagyqico[/url], [link=/]qztrksoywswa[/link], /
The basics: views and MIME-types
````````````````````````````````
&a href=&/&&jdlnjkoscwpw&/a&, [url=/]amqwmgnxzfto[/url], [link=/]rynhxfeuswye[/link], /
Remember this from Chapter 3?
&a href=&/&&fdkbkyqmdjtk&/a&, [url=/]gvxcntrwsqyp[/url], [link=/]pyifwghsfqxk[/link], /
A view function, or *view* for short, is simply a Python function that takes a Web
request and returns a Web response. This response can be the HTML contents of a Web
page, or a redirect, or a 404 error, or an XML document, or an imageor anything,
&a href=&/&&qejvtobkvwbw&/a&, [url=/]dlzojzmwyrga[/url], [link=/]oqirobubaykg[/link], /
More formally, a Django view function *must*
更正式的说,一个Django视图函数 *必须*
Accept an ``HttpRequest`` instance as its first argument
&a href=&/&&kqtxvatfbjys&/a&, [url=/]xmetnuxifndd[/url], [link=/]cdaylgqlhrfu[/link], /
Return an ``HttpResponse`` instance
&a href=&/&&smjlmhxfsroj&/a&, [url=/]jowrglroidxv[/url], [link=/]hwrgqssbsztu[/link], /
The key to returning non-HTML content from a view lies in the ``HttpResponse``
class, specifically the ``mimetype`` constructor argument. By tweaking the MIME
type, we can indicate to the browser that weve returned a response of a different
&a href=&/&&movwesvmzxul&/a&, [url=/]epwmuuwdgjxu[/url], [link=/]qyidsysoryhl[/link], /
For example, lets look at a view that returns a PNG image. To keep things simple,
well just read the file off the disk:
&a href=&/&&acdgrbpaadkv&/a&, [url=/]ukbybyuhexfm[/url], [link=/]yigxmwmekanx[/link], /
Thats it! If you replace the image path in the ``open()`` call with a path to a
real image, you can use this very simple view to serve an image, and the browser
will display it correctly.
&a href=&/&&wuhyrlxojhjt&/a&, [url=/]pjdnpntqlbmm[/url], [link=/]vzsmgmmovbqb[/link], /
The other important thing to keep in mind is that ``HttpResponse`` objects
implement Pythons standard file API. This means that you can use an
``HttpResponse`` instance in any place Python (or a third-party library) expects a
&a href=&/&&yikzqiuuowfn&/a&, [url=/]wqedmdpwirfr[/url], [link=/]ttsgstiivhgr[/link], /
For an example of how that works, lets take a look at producing CSV with Django.
&a href=&/&&hhtqsptmiqjo&/a&, [url=/]imkoefiwaqhs[/url], [link=/]vbkeqbdivhyq[/link], /
Producing CSV
`````````````
&a href=&/&&hacqxizazzxa&/a&, [url=/]nblnwuissoyp[/url], [link=/]rpdrpzoiokhp[/link], /
CSV is a simple data format usually used by spreadsheet software. Its basically a
series of table rows, with each cell in the row separated by a comma (CSV stands
for *comma-separated values* ). For example, heres some data on unruly airline
passengers in CSV format:
&a href=&/&&kwsgvmqaqdgu&/a&, [url=/]mkovshyucttr[/url], [link=/]rfeojbkzmprz[/link], /
&a href=&/&&ycypwxbsqeck&/a&, [url=/]ltqznyoskghd[/url], [link=/]kbjlpdvmvdkd[/link], /
The preceding listing c they come courtesy of the US Federal
Aviation Administration. See
`http://www.faa.gov/data_statistics/passengers_cargo/unruly_passengers/`_.
&a href=&/&&iufwuvssxuii&/a&, [url=/]ddpuqlympqpb[/url], [link=/]aqylfzybvgey[/link], /
Though CSV looks simple, its not a format thats ever been formally defined.
Different pieces of software produce and consume different variants of CSV, making
it a bit tricky to use. Luckily, Python comes with a standard CSV library, ``csv``
, that is pretty much bulletproof.
&a href=&/&&zjaqiftuujwv&/a&, [url=/]ytirbqqkqmkf[/url], [link=/]cjzrvahejiwd[/link], /
Because the ``csv`` module operates on file-like objects, its a snap to use an
``HttpResponse`` instead:
&a href=&/&&guazcimyjnxv&/a&, [url=/]vybbzzsweccp[/url], [link=/]hcwhupqafbtc[/link], /
The code and comments should be pretty clear, but a few things deserve special
&a href=&/&&qxopdsdkpixz&/a&, [url=/]nepcjkzwbozu[/url], [link=/]oornglyyjdeg[/link], /
The response is given the ``text/csv`` MIME type (instead of the default
``text/html`` ). This tells browsers that the document is a CSV file.
&a href=&/&&vuduofcbrihd&/a&, [url=/]mvxsuxkpxdib[/url], [link=/]xiorjjxrtgcy[/link], /
The response gets an additional ``Content-Disposition`` header, which contains
the name of the CSV file. This header (well, the attachment part) will instruct
the browser to prompt for a location to save the file (instead of just
displaying it). This fi call it whatever you want. It will
be used by browsers in the Save As dialog.
响应会有一个附加的 ``Content-Disposition`` 头部,它包含有CSV文件的文件名。这个头部(或者说,附加部分)会指示浏览器弹出对话框询问文件存放的位置(而不仅仅是显示)。这个文件名是任意的,它会用在浏览器的另存为对话框中。
Hooking into the CSV-generation API is easy: just pass ``response`` as the
first argument to ``csv.writer`` . The ``csv.writer`` function expects a
filelike object, and ``HttpResponse`` objects fit the bill.
&a href=&/&&ilghcremgjmx&/a&, [url=/]zdddyvlodpva[/url], [link=/]ioabdhfwugft[/link], /
For each row in your CSV file, call ``writer.writerow`` , passing it an
iterable object such as a list or tuple.
&a href=&/&&hkrlysvvgzuz&/a&, [url=/]vpipdzabsffu[/url], [link=/]atsbobchaoab[/link], /
The CSV module takes care of quoting for you, so you dont have to worry about
escaping strings with quotes or commas in them. Just pass information to
``writerow()`` , and it will do the right thing.
&a href=&/&&qdqouivxzhkk&/a&, [url=/]jywrixfvdvzu[/url], [link=/]axgvbydqhjds[/link], /
This is the general pattern youll use any time you need to return non-HTML content:
create an ``HttpResponse`` response object (with a special MIME type), pass it to
something expecting a file, and then return the response.
在任何需要返回非 HTML 内容的时候,都需要经过以下几步:创建一个 ``HttpResponse``
响应对象(需要指定特殊的 MIME 类型)。将它作为参数传给一个需要文件的方法,然后返回这个响应。
Lets look at a few more examples.
&a href=&/&&bkstrtemdvde&/a&, [url=/]lvxcbphtzzzz[/url], [link=/]xkwlasufleav[/link], /
Generating PDFs
```````````````
&a href=&/&&oxxwmpltwgnk&/a&, [url=/]pmvvhswtdvcg[/url], [link=/]jjivbvkljlop[/link], /
Portable Document Format (PDF) is a format developed by Adobe thats used to
represent printable documents, complete with pixel-perfect formatting, embedded
fonts, and 2D vector graphics. You can think of a PDF document as the digital
equivalent o indeed, PDFs are usually used when you need to
give a document to someone else to print.
&a href=&/&&dhxjiwpcdinn&/a&, [url=/]ldgzeykvdrlc[/url], [link=/]asbnduwxxhty[/link], /
You can easily generate PDFs with Python and Django thanks to the excellent open
source ReportLab library (`http://www.reportlab.org/rl_toolkit.html`_). The
advantage of generating PDF files dynamically is that you can create customized
PDFs for different purposes say, for different users or different pieces of
&a href=&/&&mckpurhfdzvq&/a&, [url=/]tzfbobjlwacy[/url], [link=/]kdizdwzavzke[/link], /
For example, we used Django and ReportLab
to generate customized,
printer-ready NCAA tournament brackets.
&a href=&/&&njlnaydnkvbf&/a&, [url=/]uijwcvewqmry[/url], [link=/]wptmzsieprqs[/link], /
Installing ReportLab
''''''''''''''''''''
&a href=&/&&dsedyiyaxiul&/a&, [url=/]iaorwvsrwvms[/url], [link=/]xtcktckybwel[/link], /
Before you do any PDF generation, however, youll need to install ReportLab. Its
usually pretty simple: just download and install the library from
`http://www.reportlab.org/downloads.html`_.
&a href=&/&&lfezipkxovqz&/a&, [url=/]dncjpxgvtzmn[/url], [link=/]woguyfycpvrn[/link], /
The user guide (naturally available only as a PDF file) at
`http://www.reportlab.org/rsrc/userguide.pdf`_ has additional installation
instructions.
&a href=&/&&motrfytqnijr&/a&, [url=/]jyjvxnfrvytp[/url], [link=/]yconcaiccbej[/link], /
&a href=&/&&aidsjeuyjwfm&/a&, [url=/]kzhpynhhtudb[/url], [link=/]zfjybkgelpdw[/link], /
If youre using a modern Linux distribution, you might want to check your package
management utility before installing ReportLab. Most package repositories have
added ReportLab.
&a href=&/&&eitzojogncwg&/a&, [url=/]bfipcrajfixw[/url], [link=/]dpegomwhcorm[/link], /
For example, if youre using the (excellent) Ubuntu distribution, a simple ``apt-get
install python-reportlab`` will do the trick nicely.
比如,如果使用(杰出的) Ubuntu 发行版,只需要简单的 ``apt-get
install python-reportlab`` 一行命令即可完成安装。
Test your installation by importing it in the Python interactive interpreter:
&a href=&/&&eypnedpsvnzc&/a&, [url=/]ryeosvrmnczx[/url], [link=/]qvfkjekroyvl[/link], /
If that command doesnt raise any errors, the installation worked.
&a href=&/&&skcbwutleksa&/a&, [url=/]bvtbgunnvwuu[/url], [link=/]aabxydiyptrm[/link], /
Writing Your View
'''''''''''''''''
&a href=&/&&psnbixbyjfqe&/a&, [url=/]ijfuheakgmbs[/url], [link=/]iyreovdatcsi[/link], /
Like CSV, generating PDFs dynamically with Django is easy because the ReportLab API
acts on filelike objects.
&a href=&/&&ctqzbaxtieci&/a&, [url=/]hxlbgjrtndoo[/url], [link=/]hksvhuhoomew[/link], /
Heres a Hello World example:
&a href=&/&&jhapthekmoxb&/a&, [url=/]kmytnfiemwfw[/url], [link=/]sgbalypqoaav[/link], /
A few notes are in order:
&a href=&/&&jnylugirorcm&/a&, [url=/]xwtiuvqwjtzm[/url], [link=/]fojolqjcjemm[/link], /
Here we use the ``application/pdf`` MIME type. This tells browsers that the
document is a PDF file, rather than an HTML file. If you leave off this
information, browsers will probably interpret the response as HTML, which will
result in scary gobbledygook in the browser window.
&a href=&/&&qwqiyshzikjm&/a&, [url=/]enfrhlixmpkh[/url], [link=/]xczyhfqgaxof[/link], /
Hooking into the ReportLab API is easy: just pass ``response`` as the first
argument to ``canvas.Canvas`` . The ``Canvas`` class expects a filelike object,
and ``HttpResponse`` objects fit the bill.
&a href=&/&&rnrqmlanjetq&/a&, [url=/]qypffkaqiaen[/url], [link=/]amujcmetbonc[/link], /
All subsequent PDF-generation methods are called on the PDF object (in this
case, ``p`` ), not on ``response`` .
&a href=&/&&jzrtjjidejoe&/a&, [url=/]xhkvuocodory[/url], [link=/]isdlhbolpdee[/link], /
Finally, its important to call ``showPage()`` and ``save()`` on the PDF file
(or else youll end up with a corrupted PDF file).
&a href=&/&&iwuigrgtjcge&/a&, [url=/]celbkpjurdgs[/url], [link=/]pgtooduoqvkv[/link], /
Complex PDFs
''''''''''''
&a href=&/&&kcimwaaxvkac&/a&, [url=/]hcehbbdbulob[/url], [link=/]ycsmqslepuxg[/link], /
If youre creating a complex PDF document (or any large data blob), consider using
the ``cStringIO`` library as a temporary holding place for your PDF file. The
``cStringIO`` library provides a file-like object interface that is written in C
for maximum efficiency.
&a href=&/&&nkzubkdzdxkx&/a&, [url=/]hurkcamotmbe[/url], [link=/]eazugefbihnm[/link], /
Heres the previous Hello World example rewritten to use ``cStringIO`` :
&a href=&/&&xtwtmlpyspmy&/a&, [url=/]mdzwjdwgwcbs[/url], [link=/]onpsixomaapp[/link], /
Other Possibilities
```````````````````
&a href=&/&&zsycndzghbpy&/a&, [url=/]fguvqabtuiop[/url], [link=/]xfdyqlyzfkjk[/link], /
Theres a whole host of other types of content you can generate in Python. Here are
a few more ideas and some pointers to libraries you could use to implement them:
&a href=&/&&cnggtqddjypn&/a&, [url=/]dlqlphcqzqdf[/url], [link=/]ewxurinqxrkh[/link], /
*ZIP files* : Pythons standard library ships with the ``zipfile`` module, which
can both read and write compressed ZIP files. You could use it to provide
on-demand archives of a bunch of files, or perhaps compress large documents
when requested. You could similarly produce TAR files using the standard
library ``tarfile`` module.
&a href=&/&&asonwegkqyzh&/a&, [url=/]fixappijeisi[/url], [link=/]wrszghdjmezc[/link], /
*Dynamic images* : The Python Imaging Library (PIL;
`/products/pil/`_) is a fantastic toolkit for
producing images (PNG, JPEG, GIF, and a whole lot more). You could use it to
automatically scale down images into thumbnails, composite multiple images into
a single frame, or even do Web-based image processing.
&a href=&/&&kbnlbhgvzswv&/a&, [url=/]ctlxbdevbigy[/url], [link=/]iqshowvukbpl[/link], /
*Plots and charts* : There are a number of incredibly powerful Python plotting
and charting libraries you could use to produce on-demand maps, charts, plots,
and graphs. We cant possibly list them all, so here are a couple of the
highlights:
&a href=&/&&aixisaiztsow&/a&, [url=/]vshaehxmjehz[/url], [link=/]bdlkditzncpm[/link], /
``matplotlib`` (`http://matplotlib.sourceforge.net/`_) can be used to
produce the type of high-quality plots usually generated with MatLab or
Mathematica.
&a href=&/&&ydqkfzdroztz&/a&, [url=/]nkhtfvlkvzfh[/url], [link=/]eqmypaxkbyeg[/link], /
``pygraphviz`` (`https://networkx.lanl.gov/wiki/pygraphviz`_), an interface
to the Graphviz graph layout toolkit (`http://graphviz.org/`_), can be used
for generating structured diagrams of graphs and networks.
&a href=&/&&zdhwikmwjcbb&/a&, [url=/]jvtvwscrzvaz[/url], [link=/]qsjvbuchafay[/link], /
In general, any Python library capable of writing to a file can be hooked into
Django. The possibilities really are endless.
&a href=&/&&cskgruapmdfr&/a&, [url=/]ydrzankxgesn[/url], [link=/]sowdkjfgyejv[/link], /
Now that weve looked at the basics of generating non-HTML content, lets step up a
level of abstraction. Django ships with some pretty nifty built-in tools for
generating some common types of non-HTML content.
&a href=&/&&cogfddvmkhwf&/a&, [url=/]tzbjzooevmfr[/url], [link=/]onddggzanpxv[/link], /
The Syndication Feed Framework
``````````````````````````````
&a href=&/&&gibmyguukagv&/a&, [url=/]abhjtcwdukdc[/url], [link=/]jkdkeevsqbxu[/link], /
Django comes with a high-level syndication-feed-generating framework that makes
creating RSS and Atom feeds easy.
&a href=&/&&ultqcueegnem&/a&, [url=/]ijzlslssujqx[/url], [link=/]byyifeehnkfh[/link], /
Whats RSS? Whats Atom?
&a href=&/&&vnadydcxzqfk&/a&, [url=/]gxlywgumshgd[/url], [link=/]ywhykzhzngpn[/link], /
RSS and Atom are both XML-based formats you can use to provide automatically
updating feeds of your sites content. Read more about RSS at
`/`_, and get information on Atom at
`http://www.atomenabled.org/`_.
&a href=&/&&gpwcyiovipyi&/a&, [url=/]iqidvywrhwqp[/url], [link=/]fucsvlyqxoyy[/link], /
To create any syndication feed, all you have to do is write a short Python class.
You can create as many feeds as you want.
&a href=&/&&kqiwfsznismp&/a&, [url=/]mhrawsrfzzje[/url], [link=/]aoavelkehdbk[/link], /
The high-level feed-generating framework is a view thats hooked to ``/feeds/`` by
convention. Django uses the remainder of the URL (everything after ``/feeds/`` ) to
determine which feed to return.
&a href=&/&&gxesscwleqis&/a&, [url=/]iktoetkagtyk[/url], [link=/]vvlhlpxgnwbj[/link], /
To create a feed, youll write a ``Feed`` class and point to it in your URLconf (see
Chapters 3 and 8 for more about URLconfs).
&a href=&/&&yvsttgthccto&/a&, [url=/]npwyzvsnmoxq[/url], [link=/]zhvjnsxtovms[/link], /
Initialization
''''''''''''''
&a href=&/&&xqunzoshzuom&/a&, [url=/]yrqipgkthyba[/url], [link=/]pdfxrybtyuap[/link], /
To activate syndication feeds on your Django site, add this URLconf:
&a href=&/&&zuqwyzvbmcqc&/a&, [url=/]rgafpjevyaru[/url], [link=/]hnvebhhlfnzq[/link], /
This line tells Django to use the RSS framework to handle all URLs starting with
``&feeds/&`` . (You can change that ``&feeds/&`` prefix to fit your own needs.)
&a href=&/&&eriuoarlyaxg&/a&, [url=/]cixuxuywzkqr[/url], [link=/]ptdpptuqujfo[/link], /
This URLconf line has an extra argument: ``{'feed_dict': feeds}`` . Use this extra
argument to pass the syndication framework the feeds that should be published under
&a href=&/&&mqaaoqqnjcwk&/a&, [url=/]cigclfomfdao[/url], [link=/]baargkfonemq[/link], /
Specifically, ``feed_dict`` should be a dictionary that maps a feeds slug (short
URL label) to its ``Feed`` class. You can define the ``feed_dict`` in the URLconf
itself. Heres a full example URLconf:
&a href=&/&&nfzcsbmuuqhf&/a&, [url=/]rsguhyqbzmlp[/url], [link=/]pwuwplhrzwqe[/link], /
The preceding example registers two feeds:
&a href=&/&&eduquapkuzdx&/a&, [url=/]kuyvofytueek[/url], [link=/]lfhkwnwdyxlw[/link], /
The feed represented by ``LatestEntries`` will live at ``feeds/latest/`` .
&a href=&/&&jbgofnpoazjj&/a&, [url=/]bvtugbzondgx[/url], [link=/]qsqcmqkoacuu[/link], /
The feed represented by ``LatestEntriesByCategory`` will live at
``feeds/categories/`` .
&a href=&/&&rihfctfwvwvg&/a&, [url=/]afrulrhzeeqa[/url], [link=/]oqrmqqtrgkob[/link], /
Once thats set up, youll need to define the ``Feed`` classes themselves.
&a href=&/&&rkggwymxkkvn&/a&, [url=/]obkdjmpjyvyo[/url], [link=/]kzysxoiypyha[/link], /
A ``Feed`` class is a simple Python class that represents a syndication feed. A
feed can be simple (e.g., a site news feed, or a basic feed displaying the latest
entries of a blog) or more complex (e.g., a feed displaying all the blog entries in
a particular category, where the category is variable).
&a href=&/&&kdzqfxwvxtlh&/a&, [url=/]kluznfhpnakk[/url], [link=/]havqbmjbgczr[/link], /
``Feed`` classes must subclass ``django.contrib.syndication.feeds.Feed`` . They can
live anywhere in your code tree.
&a href=&/&&msjfuawbahjq&/a&, [url=/]fcnpxhhycwrr[/url], [link=/]sumqvelbzlfw[/link], /
A Simple Feed
'''''''''''''
&a href=&/&&lvprdshfltxi&/a&, [url=/]vnouvmiekwap[/url], [link=/]xrbkstkezcyi[/link], /
This simple example, taken from chicagocrime.org, describes a feed of the latest
five news items:
例子来自于chicagocrime.org,描述最近5项新闻条目的feed:
The important things to notice here are as follows:
&a href=&/&&wlkncpmvilvt&/a&, [url=/]emqjjdavqkdx[/url], [link=/]bnlgivqbgquj[/link], /
The class subclasses ``django.contrib.syndication.feeds.Feed`` .
&a href=&/&&fwccmtcsmlst&/a&, [url=/]asaajsouibow[/url], [link=/]mbdfpkufokgt[/link], /
``title`` , ``link`` , and ``description`` correspond to the standard RSS
``&title&`` , ``&link&`` , and ``&description&`` elements, respectively.
&a href=&/&&psrpaiqhkneb&/a&, [url=/]kcyxynwtqfhe[/url], [link=/]dctwkisozzoj[/link], /
``items()`` is simply a method that returns a list of objects that should be
included in the feed as ``&item&`` elements. Although this example returns
``NewsItem`` objects using Djangos database API, ``items()`` doesnt have to
return model instances.
&a href=&/&&hedviqvinhra&/a&, [url=/]xyrookncbniu[/url], [link=/]mxcsiuwfkgie[/link], /
translating....
You do get a few bits of functionality for free by using Django models, but
``items()`` can return any type of object you want.
&a href=&/&&qkfgozxppomj&/a&, [url=/]qpscstjsfeer[/url], [link=/]vkzfkyhgcflw[/link], /
Theres just one more step. In an RSS feed, each ``&item&`` has a ``&title&`` ,
``&link&`` , and ``&description&`` . We need to tell the framework what data to put
into those elements.
&a href=&/&&vwcauwlkoybu&/a&, [url=/]qhniduscjwav[/url], [link=/]ktqlziufichw[/link], /
To specify the contents of ``&title&`` and ``&description&`` , create Django
templates (see Chapter 4) called ``feeds/latest_title.html`` and
``feeds/latest_description.html`` , where ``latest`` is the ``slug`` specified
in the URLconf for the given feed. Note that the ``.html`` extension is
&a href=&/&&hiqulwjtlmjd&/a&, [url=/]lnkhypujfcyc[/url], [link=/]bkgqcjdupovb[/link], /
The RSS system renders that template for each item, passing it two template
context variables:
&a href=&/&&bkaqsbdfmhit&/a&, [url=/]fmhsjuxdhtcg[/url], [link=/]lymuqpgdjdlb[/link], /
``obj`` : The current object (one of whichever objects you returned in
``items()`` ).
&a href=&/&&eapgmwmzzimw&/a&, [url=/]jxvfnxrlaasg[/url], [link=/]bupyyzqffqmh[/link], /
``site`` : A ``django.models.core.sites.Site`` object representing the
current site. This is useful for ``{{ site.domain }}`` or ``{{ site.name
&a href=&/&&ypyyvpouvqaz&/a&, [url=/]hjhhwonigurw[/url], [link=/]fdspoabwrrys[/link], /
If you dont create a template for either the title or description, the
framework will use the template ``&{{ obj }}&`` by default that is, the normal
string representation of the object.
&a href=&/&&bitisoquopsk&/a&, [url=/]hcoozmgsebwf[/url], [link=/]acyeixveoupr[/link], /
You can also change the names of these two templates by specifying
``title_template`` and ``description_template`` as attributes of your ``Feed``
&a href=&/&&nugwaawsyyoo&/a&, [url=/]xcipzgvzsinc[/url], [link=/]yuojzgrganda[/link], /
To specify the contents of ``&link&`` , you have two options. For each item in
``items()`` , Django first tries executing a ``get_absolute_url()`` method on
that object. If that method doesnt exist, it tries calling a method
``item_link()`` in the ``Feed`` class, passing it a single parameter, ``item``
, which is the object itself.
&a href=&/&&nevhonkwzolz&/a&, [url=/]ehvhsylxolre[/url], [link=/]zgvgptedtmde[/link], /
Both ``get_absolute_url()`` and ``item_link()`` should return the items URL as
a normal Python string.
``get_absolute_url()`` 和 ``item_link()`` 都应该以Python字符串形式返回URL。
For the previous ``LatestEntries`` example, we could have very simple feed
templates. ``latest_title.html`` contains:
对于前面提到的 ``LatestEntries`` 例子,我们可以实现一个简单的feed模板。 ``latest_title.html`` 包括:
and ``latest_description.html`` contains:
并且 ``latest_description.html`` 包含:
Its almost *too* easy
这真是 *太* 简单了!
A More Complex Feed
'''''''''''''''''''
一个更复杂的Feed
'''''''''''''''''''
The framework also supports more complex feeds, via parameters.
框架通过参数支持更加复杂的feeds。
translating....
For example, chicagocrime.org offers an RSS feed of recent crimes for every police
beat in Chicago. It would be silly to create a separate ``Feed`` class for each
that would violate the Dont Repeat Yourself (DRY) principle and would
couple data to programming logic.
举个例子,chicagocrime.org提供了一个RSS源以跟踪每一片区域的犯罪近况。如果为每一个单独的区域建立一个 ``Feed`` 类就显得很不明智。这样做就违反了DRY原则了,程序逻辑也会和数据耦合在一起。
Instead, the syndication framework lets you make generic feeds that return items
based on information in the feeds URL.
取而代之的方法是,使用聚合框架来产生一个通用的源,使其可以根据feeds URL返回相应的信息。
On chicagocrime.org, the police-beat feeds are accessible via URLs like this:
在chicagocrime这个例子中,区域信息可以通过这样的URL方式来访问:
``http://www.chicagocrime.org/rss/beats/0613/`` : Returns recent crimes for
``http://www.chicagocrime.org/rss/beats/0613/`` :返回0613号地区的犯罪数据
``http://www.chicagocrime.org/rss/beats/1424/`` : Returns recent crimes for
``http://www.chicagocrime.org/rss/beats/1424/`` :返回1424号地区的犯罪数据
The slug here is ``&beats&`` . The syndication framework sees the extra URL bits
after the slug ``0613`` and ``1424`` and gives you a hook to tell it what those URL
bits mean and how they should influence which items get published in the feed.
固定的那一部分是 ``&beats&`` (区域)。聚合框架看到了后面的不同之处 ``0613`` 和 ``1424`` ,它会提供给你一个钩子函数来描述这些URL的意义,以及会对feed中的项产生的影响。
An example makes this clear. Heres the code for these beat-specific feeds:
举个例子会澄清一切。下面是每个地区特定的feeds:
Heres the basic algorithm the RSS framework, given this class and a request to the
URL ``/rss/beats/0613/`` :
以下是RSS框架的基本算法,我们假设通过URL ``/rss/beats/0613/`` 来访问这个类:
The framework gets the URL ``/rss/beats/0613/`` and notices theres an extra bit
of URL after the slug. It splits that remaining string by the slash character
(``&/&`` ) and calls the ``Feed`` classs ``get_object()`` method, passing it
框架获得了URL ``/rss/beats/0613/`` 并且注意到URL中的slug部分后面含有更多的信息。它将斜杠(``&/&`` )作为分隔符,把剩余的字符串分割开作为参数,调用 ``Feed`` 类的 ``get_object()`` 方法。
In this case, bits is ``['0613']`` . For a request to
``/rss/beats/0613/foo/bar/`` , bits would be ``['0613', 'foo', 'bar']`` .
在这个例子中,添加的信息是 ``['0613']`` 。对于 ``/rss/beats/0613/foo/bar/`` 的一个URL请求, 这些信息就是 ``['0613', 'foo', 'bar']`` 。
``get_object()`` is responsible for retrieving the given beat, from the given
``bits`` .
``get_object()`` 就根据给定的 ``bits`` 值来返回区域信息。
In this case, it uses the Django database API to retrieve the beat. Note that
``get_object()`` should raise ``django.core.exceptions.ObjectDoesNotExist`` if
given invalid parameters. Theres no ``try`` /``except`` around the
``Beat.objects.get()`` call, because its not necessary. That function raises
``Beat.DoesNotExist`` on failure, and ``Beat.DoesNotExist`` is a subclass of
``ObjectDoesNotExist`` . Raising ``ObjectDoesNotExist`` in ``get_object()``
tells Django to produce a 404 error for that request.
在这个例子中,它使用了Django的数据库API来获取信息。注意到如果给定的参数不合法, ``get_object()`` 会抛出 ``django.core.exceptions.ObjectDoesNotExist`` 异常。在 ``Beat.objects.get()`` 调用中也没有出现 ``try`` /``except`` 代码块。函数在出错时抛出 ``Beat.DoesNotExist`` 异常,而 ``Beat.DoesNotExist`` 是 ``ObjectDoesNotExist`` 异常的一个子类型。 而在 ``get_object()``
中抛出 ``ObjectDoesNotExist`` 异常又会使得Django引发404错误。
To generate the feeds ``&title&`` , ``&link&`` , and ``&description&`` , Django
uses the ``title()`` , ``link()`` , and ``description()`` methods. In the
previous example, they were simple string class attributes, but this example
illustrates that they can be either strings *or* methods. For each of ``title``
, ``link`` , and ``description`` , Django follows this algorithm:
为产生 ``&title&`` , ``&link&`` , 和 ``&description&`` 的feeds, Django使用 ``title()`` , ``link()`` , 和 ``description()`` 方法。 在上面的例子中,它们都是简单的字符串类型的类属性,而这个例子表明,它们既可以是字符串, *也可以是* 方法。对于每一个 ``title`` , ``link`` 和 ``description`` 的组合,Django使用以下的算法:
It tries to call a method, passing the ``obj`` argument, where ``obj`` is
the object returned by ``get_object()`` .
试图调用一个函数,并且以 ``get_object()`` 返回的对象作为参数传递给
``obj`` 参数。
Failing that, it tries to call a method with no arguments.
如果没有成功,则不带参数调用一个方法。
Failing that, it uses the class attribute.
还不成功,则使用类属性。
Finally, note that ``items()`` in this example also takes the ``obj`` argument.
The algorithm for ``items`` is the same as described in the previous step
first, it tries ``items(obj)`` , then ``items()`` , and then finally an
``items`` class attribute (which should be a list).
最后,值得注意的是,这个例子中的 ``items()`` 使用 ``obj`` 参数。对于 ``items`` 的算法就如同上面第一步所描述的那样,首先尝试 ``items(obj)`` , 然后是 ``items()`` ,最后是 ``items`` 类属性(必须是一个列表)。
Full documentation of all the methods and attributes of the ``Feed`` classes is
always available from the official Django documentation
(`/documentation/0.96/syndication_feeds/`_).
``Feed`` 类所有方法和属性的完整文档,请参考官方的Django文档 (`/documentation/0.96/syndication_feeds/`_) 。
Specifying the Type of Feed
'''''''''''''''''''''''''''
指定Feed的类型
'''''''''''''''''''''''''''
By default, the syndication framework produces RSS 2.0. To change that, add a
``feed_type`` attribute to your ``Feed`` class:
默认情况下, 聚合框架生成RSS 2.0. 要改变这样的情况, 在 ``Feed`` 类中添加一个 ``feed_type`` 属性.
Note that you set ``feed_type`` to a class object, not an instance. Currently
available feed types are shown in Table 11-1.
注意你把 ``feed_type`` 赋值成一个类对象,而不是类实例。目前合法的Feed类型如表11-1所示。
.. table:: Table 11-1. Feed Types
+-------------------------------------------------+------------------+
|Feed Class
+=================================================+==================+
|``django.utils.feedgenerator.Rss201rev2Feed``
|RSS 2.01 (default)|
+-------------------------------------------------+------------------+
|``django.utils.feedgenerator.RssUserland091Feed``|RSS 0.91
+-------------------------------------------------+------------------+
|``django.utils.feedgenerator.Atom1Feed``
+-------------------------------------------------+------------------+
.. table:: 表 11-1. Feed 类型
+-------------------------------------------------+------------------+
+=================================================+==================+
|``django.utils.feedgenerator.Rss201rev2Feed``
|RSS 2.01 (default)|
+-------------------------------------------------+------------------+
|``django.utils.feedgenerator.RssUserland091Feed``|RSS 0.91
+-------------------------------------------------+------------------+
|``django.utils.feedgenerator.Atom1Feed``
+-------------------------------------------------+------------------+
Enclosures
''''''''''
''''''''''
To specify enclosures (i.e., media resources associated with a feed item such as
MP3 podcast feeds), use the ``item_enclosure_url`` , ``item_enclosure_length`` ,
and ``item_enclosure_mime_type`` hooks, for example:
为了指定闭包(例如,与feed项比方说MP3 feeds相关联的媒体资源信息),使用 ``item_enclosure_url`` , ``item_enclosure_length`` ,
以及 ``item_enclosure_mime_type`` ,比如
This assumes, of course, that youve created a ``Song`` object with ``song_url`` and
``song_length`` (i.e., the size in bytes) fields.
当然,你首先要创建一个包含有 ``song_url`` 和 ``song_length`` (比如按照字节计算的长度)域的 ``Song`` 对象。
''''''''
''''''''
Feeds created by the syndication framework automatically include the appropriate
``&language&`` tag (RSS 2.0) or ``xml:lang`` attribute (Atom). This comes directly
from your ``LANGUAGE_CODE`` setting.
聚合框架自动创建的Feed包含适当的 ``&language&`` 标签(RSS 2.0) 或 ``xml:lang`` 属性(Atom).
他直接来自于您的
``LANGUAGE_CODE``
''''
''''
The ``link`` method/attribute can return either an absolute URL (e.g., ``&/blog/&``
) or a URL with the fully qualified domain and protocol (e.g.,
``&/blog/&`` ). If ``link`` doesnt return the domain, the
syndication framework will insert the domain of the current site, according to your
``SITE_ID`` setting.
``link`` 方法/属性可以以绝对URL的形式(例如, ``&/blog/&`` )或者指定协议和域名的URL的形式返回(例如
``&/blog/&`` )。如果 ``link`` 没有返回域名,聚合框架会根据 ``SITE_ID`` 设置,自动的插入当前站点的域信息。
Atom feeds require a ``&link rel=&self&&`` that defines the feeds current location.
The syndication framework populates this automatically, using the domain of the
current site according to the ``SITE_ID`` setting.
Atom feeds需要 ``&link rel=&self&&`` 指明feeds现在的位置。聚合框架根据 ``SITE_ID`` 的设置,使用站点的域名自动完成这些功能。
Publishing Atom and RSS Feeds in Tandem
'''''''''''''''''''''''''''''''''''''''
同时发布Atom and RSS
Some developers like to make available both Atom *and* RSS versions of their feeds.
Thats easy to do with Django: just create a subclass of your ``feed`` class and set
the ``feed_type`` to something different. Then update your URLconf to add the extra
versions. Heres a full example:
一些开发人员想 *同时* 支持Atom和RSS。这在Django中很容易实现:只需创建一个你的 ``feed`` 类的子类,然后修改 ``feed_type`` ,并且更新URLconf内容。下面是一个完整的例子:
And heres the accompanying URLconf:
这是与之相对应那个的URLconf:
The Sitemap Framework
`````````````````````
Sitemap 框架
```````````````````````
A *sitemap* is an XML file on your Web site that tells search engine indexers how
frequently your pages change and how important certain pages are in relation to
other pages on your site. This information helps search engines index your site.
*sitemap* 是你服务器上的一个XML文件,它告诉搜索引擎你的页面的更新频率和某些页面相对于其它页面的重要性。这个信息会帮助搜索引擎索引你的网站。
For example, heres a piece of the sitemap for Djangos Web site
(`/sitemap.xml`_):
例如,这是 Django 网站(`/sitemap.xml`_)sitemap的一部分:
For more on sitemaps, see `http://www.sitemaps.org/`_.
需要了解更多有关 sitemaps 的信息, 请参见
`http://www.sitemaps.org/`_.
The Django sitemap framework automates the creation of this XML file by letting you
express this information in Python code. To create a sitemap, you just need to
write a ``Sitemap`` class and point to it in your URLconf.
Django sitemap 框架允许你用 Python 代码来表述这些信息,从而自动创建这个XML文件。要创建一个 sitemap,你只需要写一个 ``Sitemap`` 类然后配置你的URLconf指向它。
Installation
''''''''''''
''''''''''''
To install the sitemap application, follow these steps:
要安装 sitemap 应用程序, 按下面的步骤进行:
Add ``'django.contrib.sitemaps'`` to your ``INSTALLED_APPS`` setting.
1. 将 ``'django.contrib.sitemaps'`` 添加到您的 ``INSTALLED_APPS`` 设置中.
translating....
Make sure ``'django.template.loaders.app_directories.load_template_source'`` is
in your ``TEMPLATE_LOADERS`` setting. Its in there by default, so youll need to
change this only if youve changed that setting.
确保 ``'django.template.loaders.app_directories.load_template_source'`` 在您的 ``TEMPLATE_LOADERS`` 设置中。默认情况下它在那里, 所以, 如果你已经改变了那个设置的话, 只需要改回来即可。
Make sure youve installed the sites framework (see Chapter 14).
3. 确定您已经安装了 sites 框架 (参见第14章).
The sitemap application doesnt install any database tables. The only reason it
needs to go into ``INSTALLED_APPS`` is so the ``load_template_source`` template
loader can find the default templates.
sitemap 应用程序没有安装任何数据库表. 它需要加入到 ``INSTALLED_APPS`` 中的唯一原因是:
``load_template_source`` 模板加载器可以找到默认的模板.
Initialization
''''''''''''''
''''''''''''''
To activate sitemap generation on your Django site, add this line to your URLconf:
要在您的Django站点中激活sitemap生成, 请在您的 URLconf 中添加这一行:
This line tells Django to build a sitemap when a client accesses ``/sitemap.xml`` .
这一行告诉 Django, 当客户访问 ``/sitemap.xml`` 的时候, 构建一个 sitemap.
The name of the sitemap file is not important, but the location is. Search engines
will only index links in your sitemap for the current URL level and below. For
instance, if ``sitemap.xml`` lives in your root directory, it may reference any URL
in your site. However, if your sitemap lives at ``/content/sitemap.xml`` , it may
only reference URLs that begin with ``/content/`` .
sitemap文件的名字无关紧要,但是它在服务器上的位置却很重要。搜索引擎只索引你的sitemap中当前URL级别及其以下级别的链接。用一个实例来说,如果 ``sitemap.xml`` 位于你的根目录,那么它将引用任何的URL。然而,如果你的sitemap位于 ``/content/sitemap.xml`` ,那么它只引用以 ``/content/`` 打头的URL。
The sitemap view takes an extra, required argument: ``{'sitemaps': sitemaps}`` .
``sitemaps`` should be a dictionary that maps a short section label (e.g., ``blog``
or ``news`` ) to its ``Sitemap`` class (e.g., ``BlogSitemap`` or ``NewsSitemap`` ).
It may also map to an *instance* of a ``Sitemap`` class (e.g.,
``BlogSitemap(some_var)`` ).
sitemap视图需要一个额外的必须的参数: ``{'sitemaps': sitemaps}`` 。 ``sitemaps`` 应该是一个字典,它把一个短的块标签(例如, ``blog``
或 ``news`` )映射到它的 ``Sitemap`` 类(例如, ``BlogSitemap`` 或 ``NewsSitemap`` )。它也可以映射到一个 ``Sitemap`` 类的实例(例如,
``BlogSitemap(some_var)`` )。
Sitemap Classes
'''''''''''''''
Sitemap 类
'''''''''''''''
A ``Sitemap`` class is a simple Python class that represents a section of entries
in your sitemap. For example, one ``Sitemap`` class could represent all the entries
of your Weblog, while another could represent all of the events in your events
``Sitemap`` 类展示了一个进入地图站点简单的Python类片断.例如,一个 ``Sitemap`` 类能展现所有日志入口,而另外一个能够调度所有的日历事件。
In the simplest case, all these sections get lumped together into one
``sitemap.xml`` , but its also possible to use the framework to generate a sitemap
index that references individual sitemap files, one per section (as described
在最简单的例子中,所有部分可以全部包含在一个
``sitemap.xml`` 中,也可以使用框架来产生一个站点地图,为每一个独立的部分产生一个单独的站点文件。
``Sitemap`` classes must subclass ``django.contrib.sitemaps.Sitemap`` . They can
live anywhere in your code tree.
``Sitemap`` 类必须是 ``django.contrib.sitemaps.Sitemap`` 的子类. 他们可以存在于您的代码树的任何地方。
For example, lets assume you have a blog system, with an ``Entry`` model, and you
want your sitemap to include all the links to your individual blog entries. Heres
how your ``Sitemap`` class might look:
例如假设你有一个blog系统,有一个 ``Entry`` 的model,并且你希望你的站点地图包含所有连到你的blog入口的超链接。你的 ``Sitemap`` 类很可能是这样的:
Declaring a ``Sitemap`` should look very similar to declaring a ``Feed`` ; thats by
声明一个 ``Sitemap`` 和声明一个 ``Feed`` 看起来很类似;这都是预先设计好的。
Like ``Feed`` classes, ``Sitemap`` members can be either methods or attributes. See
the steps in the earlier A Complex Example section for more about how this works.
如同 ``Feed`` 类一样, ``Sitemap`` 成员也既可以是方法,也可以是属性。想要知道更详细的内容,请参见上文 《一个复杂的例子》章节。
A ``Sitemap`` class can define the following methods/attributes:
``Sitemap`` 类可以定义如下 方法/属性:
``items`` (**required** ): Provides list of objects. The framework doesnt care
what *type* all that matters is that these objects get
passed to the ``location()`` , ``lastmod()`` , ``changefreq()`` , and
``priority()`` methods.
``items`` (**必需** ):提供对象列表。框架并不关心对象的 *类型* ;唯一关心的是这些对象会传递给 ``location()`` , ``lastmod()`` , ``changefreq()`` ,和 ``priority()`` 方法。
``location`` (optional): Gives the absolute URL for a given object. Here,
absolute URL means a URL that doesnt include the protocol or domain. Here are
some examples:
``location`` (可选):给定对象的绝对URL。绝对URL不包含协议名称和域名。下面是一些例子:
Good: ``'/foo/bar/'``
好的: ``'/foo/bar/'``
Bad: ``&#/foo/bar/'``
差的: ``&#/foo/bar/'``
Bad: ``'/foo/bar/'``
差的: ``'/foo/bar/'``
If ``location`` isnt provided, the framework will call the
``get_absolute_url()`` method on each object as returned by ``items()`` .
如果没有提供 ``location`` , 框架将会在每个 ``items()`` 返回的对象上调用 ``get_absolute_url()`` 方法.
``lastmod`` (optional): The objects last modification date, as a Python
``datetime`` object.
``lastmod`` (可选): 对象的最后修改日期, 作为一个Python ``datetime`` 对象.
``changefreq`` (optional): How often the object changes. Possible values (as
given by the Sitemaps specification) are as follows:
``changefreq`` (可选):对象变更的频率。可选的值如下(详见Sitemaps文档):
``'always'``
``'always'``
``'hourly'``
``'hourly'``
``'daily'``
``'daily'``
``'weekly'``
``'weekly'``
``'monthly'``
``'monthly'``
``'yearly'``
``'yearly'``
``'never'``
``'never'``
``priority`` (optional): A suggested indexing priority between ``0.0`` and
``1.0`` . The default priority of a page is ``0.5`` ; see the
`http://sitemaps.org`_ documentation for more about how ``priority`` works.
``priority`` (可选):取值范围在 ``0.0`` and ``1.0`` 之间,用来表明优先级。默认值为 ``0.5`` ;请详见 `http://sitemaps.org`_ 文档。
'''''''''
'''''''''
The sitemap framework provides a couple convenience classes for common cases. These
are described in the sections that follow.
sitemap框架提供了一些常用的类。在下一部分中会看到。
FlatPageSitemap
...............
FlatPageSitemap
...............
The ``django.contrib.sitemaps.FlatPageSitemap`` class looks at all flat pages
defined for the current site and creates an entry in the sitemap. These entries
include only the ``location`` attribute not ``lastmod`` , ``changefreq`` , or
``priority`` .
``django.contrib.sitemaps.FlatPageSitemap`` 类涉及到站点中所有的flat page,并在sitemap中建立一个入口。但仅仅只包含 ``location`` 属性,不支持 ``lastmod`` , ``changefreq`` ,或者 ``priority`` 。
See Chapter 14 for more about flat pages.
参见第16章获取有关flat page的更多的内容.
GenericSitemap
..............
GenericSitemap
..............
The ``GenericSitemap`` class works with any generic views (see Chapter 9) you
already have.
``GenericSitemap`` 与所有的通用视图一同工作(详见第9章)。
To use it, create an instance, passing in the same ``info_dict`` you pass to the
generic views. The only requirement is that the dictionary have a ``queryset``
entry. It may also have a ``date_field`` entry that specifies a date field for
objects retrieved from the ``queryset`` . This will be used for the ``lastmod``
attribute in the generated sitemap. You may also pass ``priority`` and
``changefreq`` keyword arguments to the ``GenericSitemap`` constructor to specify
these attributes for all URLs.
你可以如下使用它,创建一个实例,并通过 ``info_dict`` 传递给通用视图。唯一的要求是字典包含 ``queryset`` 这一项。也可以用 ``date_field`` 来指明从 ``queryset`` 中取回的对象的日期域。这会被用作站点地图中的 ``lastmod``
属性。你也可以向 ``GenericSitemap`` 的构造函数传递 ``priority`` 和
``changefreq`` 来指定所有URL的相应属性。
Heres an example of a URLconf using both ``FlatPageSitemap`` and ``GenericSiteMap``
(with the hypothetical ``Entry`` object from earlier):
下面是一个使用 ``FlatPageSitemap`` and ``GenericSiteMap`` (包括前面所假定的 ``Entry`` 对象)的URLconf:
Creating a Sitemap Index
''''''''''''''''''''''''
创建一个Sitemap索引
''''''''''''''''''''''''
The sitemap framework also has the ability to create a sitemap index that
references individual sitemap files, one per each section defined in your
``sitemaps`` dictionary. The only differences in usage are as follows:
sitemap框架同样可以根据 ``sitemaps`` 字典中定义的单独的sitemap文件来建立索引。用法区别如下:
You use two views in your URLconf: ``django.contrib.sitemaps.views.index`` and
``django.contrib.sitemaps.views.sitemap`` .
您在您的URLconf 中使用了两个视图: ``django.contrib.sitemaps.views.index`` 和
``django.contrib.sitemaps.views.sitemap`` .
The ``django.contrib.sitemaps.views.sitemap`` view should take a ``section``
keyword argument.
``django.contrib.sitemaps.views.sitemap`` 视图需要带一个 ``section`` 关键字参数.
Here is what the relevant URLconf lines would look like for the previous example:
这里是前面的例子的相关的 URLconf 行看起来的样子:
This will automatically generate a ``sitemap.xml`` file that references both
``sitemap-flatpages.xml`` and ``sitemap-blog.xml`` . The ``Sitemap`` classes and
the ``sitemaps`` dictionary dont change at all.
这将自动生成一个 ``sitemap.xml`` 文件, 它同时引用 ``sitemap-flatpages.xml`` 和 ``sitemap-blog.xml``
``Sitemap`` 类和 ``sitemaps`` 目录根本没有更改.
Pinging Google
''''''''''''''
通知Google
''''''''''''''
You may want to ping Google when your sitemap changes, to let it know to reindex
your site. The framework provides a function to do just that:
``django.contrib.sitemaps.ping_google()`` .
当你的sitemap变化的时候,你会想通知Google,以便让它知道对你的站点进行重新索引。框架就提供了这样的一个函数: ``django.contrib.sitemaps.ping_google()`` 。
At the time this book was written, only Google responded to sitemap pings. However,
its quite likely that Yahoo and/or MSN will soon support these pings as well.
在本书写成的时候, 只有Google可以响应sitemap更新通知。然而,Yahoo和MSN可能很快也会支持这些通知。
At that time, well likely change the name of ``ping_google()`` to something like
``ping_search_engines()`` , so make sure to check the latest sitemap documentation
at `/documentation/0.96/sitemaps/`_.
到那个时候,把“ping_google()”这个名字改成“ping_search_engines()”会比较好。所以还是到/documentation/0.96/sitemaps/ 去检查一下最新的站点地图文档。
``ping_google()`` takes an optional argument, ``sitemap_url`` , which should be the
absolute URL of your sites sitemap (e.g., ``'/sitemap.xml'`` ). If this argument
isnt provided, ``ping_google()`` will attempt to figure out your sitemap by
performing a reverse lookup on your URLconf.
``ping_google()`` 有一个可选的参数 ``sitemap_url`` ,它应该是你的站点地图的URL绝对地址(例如: ``/sitemap.xml`` )。如果不提供该参数, ``ping_google()`` 将尝试通过反查你的URLconf来找到你的站点地图。
``ping_google()`` raises the exception ``django.contrib.sitemaps.SitemapNotFound``
if it cannot determine your sitemap URL.
如果不能够确定你的sitemap URL, ``ping_google()`` 会引发 ``django.contrib.sitemaps.SitemapNotFound`` 异常。
One useful way to call ``ping_google()`` is from a models ``save()`` method:
我们可以通过模型中的 ``save()`` 方法来调用 ``ping_google()`` :
A more efficient solution, however, would be to call ``ping_google()`` from a
``cron`` script or some other scheduled task. The function makes an HTTP request to
Googles servers, so you may not want to introduce that network overhead each time
you call ``save()`` .
一个更有效的解决方案是用 ``cron`` 脚本或任务调度表来调用 ``ping_google()`` ,该方法使用Http直接请求Google服务器,从而减少每次调用 ``save()`` 时占用的网络带宽。
Whats Next?
```````````
Next, well continue to dig deeper into all the nifty built-in tools Django gives
you. Chapter 12 looks at all the tools you need to provide user-customized sites:
sessions, users, and authentication.
下面, 我们要继续深入挖掘所有的Django给你的很好的内置工具。
在第12章,您将看到提供用户自定义站点所需要的所有工具:
sessions, users 和authentication.

我要回帖

更多关于 知佳 翻译 39 的文章

 

随机推荐