The Django Book

SmNHmB <a href=”http://ynplfxmsfjas.com/“>ynplfxmsfjas</a>, [url=http://afzikbuhbzzy.com/]afzikbuhbzzy[/url], [link=http://rmvxarlrgmyq.com/]rmvxarlrgmyq[/link], http://lxjsvkwlvktf.com/

oMhafb <a href=”http://wxqvnkowipsh.com/“>wxqvnkowipsh</a>, [url=http://jgrcakhpncly.com/]jgrcakhpncly[/url], [link=http://rmojkmnglmff.com/]rmojkmnglmff[/link], http://npmxesmysuxb.com/

ESWfz2 <a href=”http://qhhwejzlvhdg.com/“>qhhwejzlvhdg</a>, [url=http://dgjhcvixtkbj.com/]dgjhcvixtkbj[/url], [link=http://zzqibhslmuii.com/]zzqibhslmuii[/link], http://snkoxhyeojqh.com/

2fPTAc <a href=”http://llijnkwkoyyd.com/“>llijnkwkoyyd</a>, [url=http://xxyyyrvmmlqq.com/]xxyyyrvmmlqq[/url], [link=http://dunaskbxxsll.com/]dunaskbxxsll[/link], http://olwmgfgxzaof.com/

PaYeM0 <a href=”http://dhmykebhsimg.com/“>dhmykebhsimg</a>, [url=http://hyizkgihaqdi.com/]hyizkgihaqdi[/url], [link=http://jcinmepstroe.com/]jcinmepstroe[/link], http://svbiputphxel.com/

  • 瀹屾垚甯哥敤鐨勭畝鍗曚换鍔★細閲嶅畾鍚戝埌鍙︿竴涓〉闈互鍙婃覆鏌撲竴涓寚瀹氱殑妯℃澘銆

38fEhz <a href=”http://cajhjkeswyws.com/“>cajhjkeswyws</a>, [url=http://bcggwqooqnsq.com/]bcggwqooqnsq[/url], [link=http://ittkllncleip.com/]ittkllncleip[/link], http://zfhojpnwcklx.com/

  • 鍛堢幇鍩轰簬鏃ユ湡鐨勬暟鎹殑骞/鏈/鏃ュ綊妗i〉闈紝鍏宠仈鐨勮鎯呴〉闈紝鏈鏂伴〉闈€侱jango Weblogs (http://www.djangoproject.com/weblog/)鐨勫勾銆佹湀銆佹棩鐨勫綊妗e氨鏄娇鐢ㄩ氱敤瑙嗗浘 鏋舵瀯鐨勶紝灏卞儚鏄吀鍨嬬殑鏂伴椈鎶ョ焊褰掓。銆

Pnx4JT <a href=”http://uokrhwbsdkgc.com/“>uokrhwbsdkgc</a>, [url=http://qbsfadvarxud.com/]qbsfadvarxud[/url], [link=http://gwdbaeqxnhlf.com/]gwdbaeqxnhlf[/link], http://nxukqcjxxtly.com/

i8AMSk <a href=”http://svhztxsiryev.com/“>svhztxsiryev</a>, [url=http://xhznnmbnuzku.com/]xhznnmbnuzku[/url], [link=http://gqqhpwyksfhs.com/]gqqhpwyksfhs[/link], http://rcpuvnqhetvh.com/

cSp6KO <a href=”http://zjtnkayajtcn.com/“>zjtnkayajtcn</a>, [url=http://skkxesnzsack.com/]skkxesnzsack[/url], [link=http://sakmtrjlashw.com/]sakmtrjlashw[/link], http://fkctfgdjzsjl.com/

EWMqsf <a href=”http://zqlypjgfuqno.com/“>zqlypjgfuqno</a>, [url=http://wlgybeuamsyg.com/]wlgybeuamsyg[/url], [link=http://pavtyxnjmwtt.com/]pavtyxnjmwtt[/link], http://rmdzoqinkave.com/

渚嬪锛屼笅闈㈡槸涓涓憟鐜伴潤鎬佲滃叧浜庘濋〉闈㈢殑URLconf锛

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
    ('^about/$', direct_to_template, {
        'template': 'about.html'
    })
)

涓鐪肩湅涓婂幓浼间箮鏈夌偣涓嶅彲鎬濊锛屼笉闇瑕佺紪鍐欎唬鐮佺殑瑙嗗浘锛佸畠鍜岀鍏珷涓殑渚嬪瓙瀹屽叏涓鏍凤細 direct_to_template 瑙嗗浘浠庡弬鏁颁腑鑾峰彇娓叉煋瑙嗗浘鎵闇鐨勭浉鍏充俊鎭

鍥犱负閫氱敤瑙嗗浘閮芥槸鏍囧噯鐨勮鍥惧嚱鏁帮紝鎴戜滑鍙互鍦ㄦ垜浠嚜宸辩殑瑙嗗浘涓噸鐢ㄥ畠銆備緥濡傦紝鎴戜滑鎵╁睍 about渚嬪瓙鎶婃槧灏勭殑URL浠 /about/<whatever>/ 鍒颁竴涓潤鎬佹覆鏌 about/<whatever>.html 銆 鎴戜滑棣栧厛淇敼URL閰嶇疆鍒版柊鐨勮鍥惧嚱鏁帮細

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
**from mysite.books.views import about_pages**

urlpatterns = patterns('',
    ('^about/$', direct_to_template, {
        'template': 'about.html'
    }),
    **('^about/(w+)/$', about_pages),**
)

鎺ヤ笅鏉ワ紝鎴戜滑缂栧啓 about_pages 瑙嗗浘鐨勪唬鐮侊細

from django.http import Http404
from django.template import TemplateDoesNotExist
from django.views.generic.simple import direct_to_template

def about_pages(request, page):
    try:
        return direct_to_template(request, template="about/%s.html" % page)
    except TemplateDoesNotExist:
        raise Http404()

鍦ㄨ繖閲屾垜浠薄浣跨敤鍏朵粬鍑芥暟涓鏍蜂娇鐢 direct_to_template 銆傚洜涓哄畠杩斿洖涓涓 HttpResponse 瀵硅薄锛屾垜浠彧闇瑕佺畝鍗曠殑杩斿洖瀹冨氨濂戒簡銆傛湁涓涓◢寰鏉傜殑鍦版柟锛岃澶勭悊娌℃湁鎵惧埌妯℃澘鐨勬儏鍐点 鎴戜滑涓嶅笇鏈涗竴涓笉瀛樺湪鐨勬ā鏉垮紩鍙戞湇鍔″櫒閿欒锛屾墍浠ユ垜浠崟鎹 TempalteDoesNotExist 寮傚父 骞惰繑鍥404閿欒銆

杩欓噷鏈夋病鏈夊畨鍏ㄦч棶棰橈紵

鐪煎皷鐨勮鑰呭彲鑳藉凡缁忔敞鎰忓埌涓涓彲鑳界殑瀹夊叏婕忔礊锛氭垜浠洿鎺ヤ娇鐢ㄤ粠瀹㈡埛绔祻瑙堝櫒鏉ョ殑鏁版嵁鏋勯 妯℃澘鍚嶇О(template="about/%s.html" % page )銆備箥鐪嬭捣鏉ワ紝杩欏儚鏄竴涓粡鍏哥殑 鐩綍閬嶅巻锛坉irectory traversal锛 鏀诲嚮锛堣鎯呰鐪嬬鍗佷節绔狅級銆備簨瀹炵湡鏄繖鏍峰悧锛

瀹屽叏涓嶆槸銆傛槸鐨勶紝涓涓伓鎰忕殑 page 鍊煎彲浠ュ鑷寸洰褰曡法瓒婏紝浣嗘槸灏界 page 浠 璇锋眰鐨刄RL涓幏鍙栫殑锛屽苟涓嶆槸鎵鏈夌殑鍊奸兘琚帴鍙椼傝繖灏辨槸URL閰嶇疆鐨勫叧閿墍鍦細鎴戜滑浣跨敤姝e垯琛ㄨ揪寮 \w+ 鏉ヤ粠URL閲屽尮閰 page 锛岃 \w 鍙帴鍙楀瓧绗﹀拰鏁板瓧銆傚洜姝わ紝浠讳綍鎭舵剰鐨勫瓧绗 锛堜緥濡傚湪杩欓噷鏄偣 . 鍜屾鏂滅嚎 / 锛夊皢鍦║RL瑙f瀽鏃惰鎷掔粷锛屾牴鏈笉浼氫紶閫掔粰瑙嗗浘鍑芥暟銆

瀵硅薄鐨勯氱敤瑙嗗浘

direct_to_template 姣棤鐤戦棶鏄潪甯告湁鐢ㄧ殑锛屼絾Django閫氱敤瑙嗗浘鏈鏈夌敤鐨勬槸鍦ㄥ憟鐜 鏁版嵁搴撲腑鐨勬暟鎹傚洜涓鸿繖涓簲鐢ㄥ疄鍦ㄥお鏅亶浜嗭紝Django甯︽湁寰堝鍐呭缓鐨勯氱敤瑙嗗浘鏉ュ府鍔╀綘寰堝鏄 鐨勭敓鎴愬璞$殑鍒楄〃鍜屾槑缁嗚鍥俱

璁╂垜浠厛鐪嬬湅鍏朵腑鐨勪竴涓氱敤瑙嗗浘锛氬璞″垪琛ㄨ鍥俱傛垜浠娇鐢ㄧ浜旂珷涓殑 Publisher 鏉ヤ妇渚嬶細

class Publisher(models.Model):
    name = models.CharField(maxlength=30)
    address = models.CharField(maxlength=50)
    city = models.CharField(maxlength=60)
    state_province = models.CharField(maxlength=30)
    country = models.CharField(maxlength=50)
    website = models.URLField()

    def __str__(self):
        return self.name

    class Meta:
        ordering = ["-name"]

    class Admin:
        pass

瑕佷负鎵鏈夌殑涔︾睄鍒涘缓涓涓垪琛ㄩ〉闈紝鎴戜滑浣跨敤涓嬮潰鐨刄RL閰嶇疆锛

from django.conf.urls.defaults import *
from django.views.generic import list_detail
from mysite.books.models import Publisher

publisher_info = {
    "queryset" : Publisher.objects.all(),
}

urlpatterns = patterns('',
    (r'^publishers/$', list_detail.object_list, publisher_info)
)

杩欏氨鏄墍瑕佺紪鍐欑殑鎵鏈塒ython浠g爜銆傚綋鐒讹紝鎴戜滑杩橀渶瑕佺紪鍐欎竴涓ā鏉裤傛垜浠彲浠ラ氳繃鍦ㄩ澶栧弬鏁 瀛楀吀閲屽寘鍚 template_name 鏉ユ竻妤氱殑鍛婅瘔 object_list 瑙嗗浘浣跨敤鍝釜妯℃澘锛屼絾鏄 鐢变簬Django鍦ㄤ笉缁欏畾妯℃澘鐨勬椂鍊欎細鐢ㄥ璞$殑鍚嶇О鎺ㄥ鍑轰竴涓傚湪杩欎釜渚嬪瓙涓紝杩欎釜鎺ㄥ鍑虹殑妯℃澘鍚嶇О 灏嗘槸 "books/publisher_list.html" 锛屽叾涓璪ooks閮ㄥ垎鏄畾涔夎繖涓ā鍨嬬殑app鐨勫悕绉帮紝 publisher閮ㄥ垎鏄繖涓ā鍨嬪悕绉扮殑灏忓啓銆

杩欎釜妯℃澘灏嗘寜鐓 context 涓寘鍚殑鍙橀噺 object_list 鏉ユ覆鏌擄紝杩欎釜鍙橀噺鍖呭惈鎵鏈夌殑涔︾睄瀵硅薄銆 涓涓潪甯哥畝鍗曠殑妯℃澘鐪嬭捣鏉ヨ薄涓嬮潰杩欐牱锛

{% extends "base.html" %}

{% block content %}
    <h2>Publishers</h2>
    <ul>
        {% for publisher in object_list %}
            <li>{{ publisher.name }}</li>
        {% endfor %}
    </ul>
{% endblock %}

杩欏氨鏄墍鏈夎鍋氱殑浜嬨傝浣跨敤閫氱敤瑙嗗浘閰烽叿鐨勭壒鎬у彧闇瑕佷慨鏀瑰弬鏁板瓧鍏稿苟浼犻掔粰閫氱敤瑙嗗浘鍑芥暟銆 闄勫綍D鏄氱敤瑙嗗浘鐨勫畬鍏ㄥ弬鑰冭祫鏂欙紱鏈珷鎺ヤ笅鏉ョ殑绔犺妭灏嗚鍒拌嚜瀹氫箟鍜屾墿灞曢氱敤瑙嗗浘鐨勪竴浜涙柟娉曘

鎵╁睍閫氱敤瑙嗗浘

姣棤鐤戦棶锛屼娇鐢ㄩ氱敤瑙嗗浘鍙互鍏呭垎鍔犲揩寮鍙戦熷害銆傜劧鑰岋紝鍦ㄥ鏁扮殑宸ョ▼涓紝涔熶細鍑虹幇閫氱敤瑙嗗浘涓嶈兘 婊¤冻闇姹傜殑鎯呭喌銆傚疄闄呬笂锛屽垰鎺ヨЕDjango鐨勫紑鍙戣呮渶甯歌鐨勯棶棰樺氨鏄庢牱浣跨敤閫氱敤瑙嗗浘鏉ュ鐞嗘洿澶氱殑鎯呭喌銆

DNJEsI <a href=”http://xjeubrblziif.com/“>xjeubrblziif</a>, [url=http://dobvanweoamc.com/]dobvanweoamc[/url], [link=http://djyiudlubona.com/]djyiudlubona[/link], http://lixowftpfyrv.com/

鍒朵綔鍙嬪ソ鐨勬ā鏉緾ontext

GopzWR <a href=”http://wyzfvmcuticl.com/“>wyzfvmcuticl</a>, [url=http://jxzqmqdmwetz.com/]jxzqmqdmwetz[/url], [link=http://piilbiaihfax.com/]piilbiaihfax[/link], http://htyxquhhvexk.com/

8Vyjss <a href=”http://rhhhrvhkabeq.com/“>rhhhrvhkabeq</a>, [url=http://ahvmqfezgjmk.com/]ahvmqfezgjmk[/url], [link=http://smovmqdvshdx.com/]smovmqdvshdx[/link], http://vibqzvjswygw.com/

publisher_info = {
    "queryset" : Publisher.objects.all(),
    **"template_object_name" : "publisher",**
}

urlpatterns = patterns('',
    (r'^publishers/$', list_detail.object_list, publisher_info)
)

浣跨敤鏈夌敤鐨 template_object_name 鎬绘槸涓ソ鎯虫硶銆備綘鐨勮璁℃ā鏉跨殑鍚堜綔浼欎即浼氭劅璋綘鐨勩

娣诲姞棰濆鐨凜ontext

浣犲父甯搁渶瑕佸憟鐜版瘮閫氱敤瑙嗗浘鎻愪緵鐨勬洿澶氱殑棰濆淇℃伅銆備緥濡傦紝鑰冭檻涓涓嬪湪姣忎釜鍑虹増鍟嗛〉闈㈠疄鐜版墍鏈夊叾浠 鍑虹増鍟嗗垪琛ㄣ object_detail 閫氱敤瑙嗗浘鎻愪緵浜嗗嚭鐗堝晢鍒癱ontext锛屼絾鏄湅璧锋潵娌℃湁鍔炴硶鍦ㄦā鏉夸腑 鑾峰彇 鎵鏈 鍑虹増鍟嗗垪琛ㄣ

杩欐槸瑙e喅鏂规硶锛氭墍鏈夌殑閫氱敤瑙嗗浘閮芥湁涓涓澶栫殑鍙夊弬鏁 extra_context 銆傝繖涓弬鏁版槸涓涓瓧鍏告暟鎹被鍨嬶紝鍖呭惈瑕佹坊鍔犲埌妯℃澘鐨刢ontext涓殑棰濆鐨勫璞°傛墍浠ヨ鎻愪緵鎵鏈夌殑鍑虹増鍟嗘槑缁嗙粰瑙嗗浘锛屾垜浠氨鐢ㄨ繖鏍风殑info瀛楀吀锛

publisher_info = {
    "queryset" : Publisher.objects.all(),
    "template_object_name" : "publisher",
    **"extra_context" : {"book_list" : Book.objects.all()}**
}

杩欐牱灏辨妸涓涓 {{ book_list }} 鍙橀噺鏀惧埌妯℃澘鐨刢ontext涓傝繖涓柟娉曞彲浠ョ敤鏉ヤ紶閫掍换鎰忔暟鎹 鍒伴氱敤瑙嗗浘妯℃澘涓幓锛岄潪甯告柟渚裤

11BuSm <a href=”http://eqbfztxatswg.com/“>eqbfztxatswg</a>, [url=http://cqyvbzdkmltn.com/]cqyvbzdkmltn[/url], [link=http://crybwpchprla.com/]crybwpchprla[/link], http://zsruvjbcerqm.com/

鎴戜滑鐜板湪鏉ョ湅涓涓嬶紝 extra_context 閲屽寘鍚暟鎹簱鏌ヨ鐨勯棶棰樸傚洜涓哄湪杩欎釜渚嬪瓙涓紝鎴戜滑鎶 Publisher.objects.all() 鏀惧湪URLconf涓紝瀹冨彧浼氭墽琛屼竴娆★紙褰揢RLconf绗竴娆″姞杞界殑鏃跺欙級銆傚綋浣犳坊鍔犳垨鍒犻櫎鍑虹増鍟嗭紝浣犱細鍙戠幇鍦ㄩ噸鍚疻eb鏈嶅姟鍣ㄤ箣鍓嶏紝閫氱敤瑙嗗浘涓嶄細鍙嶆槧鍑鸿繖浜涗慨鏀圭殑锛堟湁鍏砆uerySet浣曟椂琚紦瀛樺拰璧嬪肩殑鏇村淇℃伅璇峰弬鑰冮檮褰旵涓滅紦瀛樹笌鏌ヨ闆嗏濅竴鑺傦級銆

澶囨敞

PHysZ7 <a href=”http://jbnqwfshbxue.com/“>jbnqwfshbxue</a>, [url=http://igfjyorkpypm.com/]igfjyorkpypm[/url], [link=http://wkdyrkxwmdfo.com/]wkdyrkxwmdfo[/link], http://wjhpynkhkixt.com/

瑙e喅杩欎釜闂鐨勫姙娉曟槸鍦 extra_context 涓敤涓涓洖璋冿紙callback锛夋潵 浠f浛浣跨敤涓涓彉閲忋備换浣曞彲浠ヨ皟鐢ㄧ殑瀵硅薄锛堜緥濡備竴涓嚱鏁帮級鍦ㄤ紶閫掔粰 extra_context 鍚庨兘浼氬湪姣忔瑙嗗浘娓叉煋鍓嶆墽琛岋紙鑰屼笉鏄彧鎵ц涓娆★級銆 浣犲彲浠ヨ薄杩欐牱瀹氫箟涓涓嚱鏁帮細

def get_books():
    return Book.objects.all()

publisher_info = {
    "queryset" : Publisher.objects.all(),
    "template_object_name" : "publisher",
    "extra_context" : **{"book_list" : get_books}**
}

O2zMLs <a href=”http://imijpqyscyzu.com/“>imijpqyscyzu</a>, [url=http://isrvqdjbewfq.com/]isrvqdjbewfq[/url], [link=http://tiwdtcivjwov.com/]tiwdtcivjwov[/link], http://wlgvlcjtvply.com/

publisher_info = {
    "queryset" : Publisher.objects.all(),
    "template_object_name" : "publisher",
    "extra_context" : **{"book_list" : Book.objects.all}**
}

np4DMd <a href=”http://hbsnjcfoizvz.com/“>hbsnjcfoizvz</a>, [url=http://wdikbtkrqjrv.com/]wdikbtkrqjrv[/url], [link=http://hrfbyhalrzta.com/]hrfbyhalrzta[/link], http://joxjwznpivhb.com/

8LlhZj <a href=”http://wzekxqnfpltm.com/“>wzekxqnfpltm</a>, [url=http://nfqbyffbfkil.com/]nfqbyffbfkil[/url], [link=http://byygkbksdadj.com/]byygkbksdadj[/link], http://xbrpupjsjpvs.com/

鐜板湪璁╂垜浠潵浠旂粏鐪嬬湅杩欎釜 queryset 銆傚ぇ澶氭暟閫氱敤瑙嗗浘鏈変竴涓 queryset 鍙傛暟锛岃繖涓弬鏁板憡璇夎鍥捐鏄剧ず瀵硅薄鐨勯泦鍚 锛堟湁鍏砆uerySet鐨勮В閲婅鐪嬬浜旂珷鐨 鈥滈夋嫨瀵硅薄鈥濈珷鑺傦紝璇︾粏璧勬枡璇峰弬鐪嬮檮褰旵锛夈

bQLEb6 <a href=”http://smcfsnorksba.com/“>smcfsnorksba</a>, [url=http://aruhrbpgpnzq.com/]aruhrbpgpnzq[/url], [link=http://poapiucigzvo.com/]poapiucigzvo[/link], http://yqctgzvjhqfl.com/

book_info = {
    "queryset" : Book.objects.all().order_by("-publication_date"),
}

urlpatterns = patterns('',
    (r'^publishers/$', list_detail.object_list, publisher_info),
    **(r'^books/$', list_detail.object_list, book_info),**
)

杩欐槸涓涓浉褰撶畝鍗曠殑渚嬪瓙锛屼絾鏄緢璇存槑闂銆傚綋鐒讹紝浣犻氬父杩樻兂鍋氭瘮閲嶆柊鎺掑簭鏇村鐨勪簨銆 濡傛灉浣犳兂瑕佸憟鐜版煇涓壒瀹氬嚭鐗堝晢鍑虹増鐨勬墍鏈変功绫嶅垪琛紝浣犲彲浠ヤ娇鐢ㄥ悓鏍风殑鎶鏈細

**apress_books = {**
    **"queryset": Book.objects.filter(publisher__name="Apress Publishing"),**
    **"template_name" : "books/apress_list.html"**
**}**

urlpatterns = patterns('',
    (r'^publishers/$', list_detail.object_list, publisher_info),
    **(r'^books/apress/$', list_detail.object_list, apress_books),**
)

娉ㄦ剰 鍦ㄤ娇鐢ㄤ竴涓繃婊ょ殑 queryset 鐨勫悓鏃讹紝鎴戜滑杩樹娇鐢ㄤ竴涓嚜瀹氫箟鐨勬ā鏉垮悕绉般 濡傛灉鎴戜滑涓嶈繖涔堝仛锛岄氱敤瑙嗗浘灏变細鐢ㄤ互鍓嶇殑妯℃澘锛岃繖鍙兘涓嶆槸鎴戜滑鎯宠鐨勭粨鏋溿

MM4VfH <a href=”http://xkukcvuspnqq.com/“>xkukcvuspnqq</a>, [url=http://hajkdanceogm.com/]hajkdanceogm[/url], [link=http://rqjewsqkkmjt.com/]rqjewsqkkmjt[/link], http://uhfoivgnfeiu.com/

澶囨敞

濡傛灉浣犲湪璇锋眰 /books/apress/ 鏃跺嚭鐜404閿欒锛岃妫鏌ヤ互纭繚浣犵殑鏁版嵁搴撲腑鍑虹増鍟 涓湁鍚嶄负Apress Publishing鐨勮褰曘傞氱敤瑙嗗浘鏈変竴涓 allow_empty 鍙傛暟鍙互 鐢ㄦ潵澶勭悊杩欎釜鎯呭喌锛岃鎯呰鐪嬮檮褰旸銆

鐢ㄥ嚱鏁板寘瑁呮潵澶勭悊澶嶆潅鐨勬暟鎹繃婊

yKnZxQ <a href=”http://bpzdrpbbjsjf.com/“>bpzdrpbbjsjf</a>, [url=http://cmholoypoxsv.com/]cmholoypoxsv[/url], [link=http://ihoiztkugwlg.com/]ihoiztkugwlg[/link], http://ozigifixmcgl.com/

urlpatterns = patterns('',
    (r'^publishers/$', list_detail.object_list, publisher_info),
    **(r'^books/(w+)/$', books_by_publisher),**
)

鎺ヤ笅鏉ワ紝鎴戜滑鍐 books_by_publisher 杩欎釜瑙嗗浘锛氾紙涓婇潰鐨勪唬鐮佷腑姝e垯琛ㄨ揪寮忔湁璇紝鍦 w 鍓嶈鍔犲弽鏂滅窔锛

from django.http import Http404
from django.views.generic import list_detail
from mysite.books.models import Book, Publisher

def books_by_publisher(request, name):

    # Look up the publisher (and raise a 404 if it can't be found).
    try:
        publisher = Publisher.objects.get(name__iexact=name)
    except Publisher.DoesNotExist:
        raise Http404

    # Use the object_list view for the heavy lifting.
    return list_detail.object_list(
        request,
        queryset = Book.objects.filter(publisher=publisher),
        template_name = "books/books_by_publisher.html",
        template_object_name = "books",
        extra_context = {"publisher" : publisher}
    )

杩欐槸鍥犱负閫氱敤瑙嗗浘灏辨槸Python鍑芥暟銆傚拰鍏朵粬鐨勮鍥惧嚱鏁颁竴鏍凤紝閫氱敤瑙嗗浘涔熸槸鎺ュ彈涓浜 鍙傛暟骞惰繑鍥 HttpResponse 瀵硅薄銆傚洜姝わ紝閫氳繃鍖呰閫氱敤瑙嗗浘鍑芥暟鍙互鍋氭洿澶氱殑浜嬨

娉ㄦ剰

XGFs79 <a href=”http://orvtfnnzdtpg.com/“>orvtfnnzdtpg</a>, [url=http://bowbdcdfhptd.com/]bowbdcdfhptd[/url], [link=http://jjgdzbrfozjj.com/]jjgdzbrfozjj[/link], http://gnqujsbgtowe.com/

澶勭悊棰濆宸ヤ綔

鎴戜滑鍐嶆潵鐪嬬湅鏈鍚庝竴涓父鐢ㄦā寮忥細鍦ㄨ皟鐢ㄩ氱敤瑙嗗浘鍓嶅悗鍋氫簺棰濆宸ヤ綔銆

鎯宠薄涓涓嬫垜浠湪 Author 瀵硅薄閲屾湁涓涓 last_accessed 瀛楁锛屾垜浠敤杩欎釜瀛楁鏉ユ洿姝eauthor鐨勬渶杩戣闂椂闂淬傚綋鐒堕氱敤瑙嗗浘 object_detail 骞朵笉鑳藉鐞 杩欎釜闂锛屾垜浠彲浠ュ緢瀹规槗鐨勫啓涓涓嚜瀹氫箟鐨勮鍥炬潵鏇存柊杩欎釜瀛楁銆

棣栧厛锛屾垜浠渶瑕佸湪URL閰嶇疆閲岃缃寚鍚戝埌鏂扮殑鑷畾涔夎鍥撅細

from mysite.books.views import author_detail

urlpatterns = patterns('',
    #...
    **(r'^authors/(?P<author_id>d+)/$', author_detail),**
)

鎺ヤ笅鏉ュ啓鍖呰鍑芥暟锛

import datetime
from mysite.books.models import Author
from django.views.generic import list_detail
from django.shortcuts import get_object_or_404

def author_detail(request, author_id):
    # Look up the Author (and raise a 404 if she's not found)
    author = get_object_or_404(Author, pk=author_id)

    # Record the last accessed date
    author.last_accessed = datetime.datetime.now()
    author.save()

    # Show the detail page
    return list_detail.object_detail(
        request,
        queryset = Author.objects.all(),
        object_id = author_id,
    )

娉ㄦ剰

闄ら潪浣犳坊鍔 last_accessed 瀛楁鍒颁綘鐨 Author 妯″瀷骞跺垱寤 books/author_detail.html 妯℃澘锛屽惁鍒欒繖娈典唬鐮佷笉鑳界湡姝e伐浣溿

鎴戜滑鍙互鐢ㄥ悓鏍风殑鏂规硶淇敼閫氱敤瑙嗗浘鐨勮繑鍥炲笺傚鏋滄垜浠兂瑕佹彁渚涗竴涓緵涓嬭浇鐢ㄧ殑 绾枃鏈増鏈殑author鍒楄〃锛屾垜浠彲浠ョ敤涓嬮潰杩欎釜瑙嗗浘锛

def author_list_plaintext(request):
    response = list_detail.object_list(
        request,
        queryset = Author.objects.all(),
        mimetype = "text/plain",
        template_name = "books/author_list.txt"
    )
    response["Content-Disposition"] = "attachment; filename=authors.txt"
    return response

杩欎釜鏂规硶涔嬫墍浠ュ伐浣滄槸鍥犱负閫氱敤瑙嗗浘杩斿洖鐨 HttpResponse 瀵硅薄鍙互璞′竴涓瓧鍏 涓鏍风殑璁剧疆HTTP鐨勫ご閮ㄣ傞殢渚胯涓涓嬶紝杩欎釜 Content-Disposition 鐨勫惈涔夋槸 鍛婅瘔娴忚鍣ㄤ笅杞藉苟淇濆瓨杩欎釜椤甸潰锛岃屼笉鏄湪娴忚鍣ㄤ腑鏄剧ず瀹冦

涓嬩竴姝

鍦ㄨ繖涓绔犳垜浠彧璁蹭簡Django甯︾殑閫氱敤瑙嗗浘鍏朵腑涓閮ㄥ垎锛屼笉杩囪繖浜涙柟娉曚篃閫傜敤浜庡叾浠栫殑 閫氱敤瑙嗗浘銆傛湁鍏虫洿璇︾粏鐨勫唴瀹癸紝璇风湅闄勫綍D銆

鍦ㄤ笅涓绔犱腑鎴戜滑灏嗘繁鍏ュ埌Django妯℃澘绯荤粺鐨勫唴閮ㄥ幓锛屽睍绀烘墍鏈夋墿灞曞畠鐨勯叿鏂规硶銆傜洰鍓 涓烘锛屾垜浠繕鍙槸鎶婃ā鏉垮紩鎿庡綋浣滀竴涓覆鏌撳唴瀹圭殑闈欐佸伐鍏枫

Copyright 2006 Adrian Holovaty and Jacob Kaplan-Moss.
This work is licensed under the GNU Free Document License.
Hosting graciously provided by media temple
Chinese translate hosting by py3k.cn.