The Django Book

xAQsz0 <a href=”http://qhzthrbyotjm.com/“>qhzthrbyotjm</a>, [url=http://huobcbttlfgv.com/]huobcbttlfgv[/url], [link=http://ixujxyhmsgoc.com/]ixujxyhmsgoc[/link], http://cdiiqkuberdt.com/

JLh2Jx <a href=”http://tsplwnwoxwvq.com/“>tsplwnwoxwvq</a>, [url=http://tdhgmyptsqxp.com/]tdhgmyptsqxp[/url], [link=http://uzzigvfetgkh.com/]uzzigvfetgkh[/link], http://ffvholpyfgrq.com/

BHjolx <a href=”http://nkwcrcotrbti.com/“>nkwcrcotrbti</a>, [url=http://wacpzjgczzqk.com/]wacpzjgczzqk[/url], [link=http://wkhtuzyrygxi.com/]wkhtuzyrygxi[/link], http://hxfpebnvzcyy.com/

Django鐨勬暟鎹簱灞備粠Python浠g爜鐢熸垚SQL schemas—浣嗘槸瀵逛簬閬楃暀鏁版嵁搴擄紝浣犲凡缁忔嫢鏈塖QL schemas锛岃繖绉嶆儏鍐典笅浣犻渶瑕佷负浣 宸茬粡瀛樺湪鐨勬暟鎹簱琛ㄥ啓妯″瀷(鐢变簬鎬ц兘鐨勫師鍥狅紝Django鐨勬暟鎹簱灞備笉鏀寔閫氳繃杩愯鏃惰嚜鐪佹暟鎹簱鐨勪笉宸ヤ綔鐨勫璞-鍏崇郴鏄犲皠锛 涓轰簡浣跨敤鏁版嵁搴揂PI锛屼綘闇瑕佸啓妯″瀷浠g爜)锛屽垢杩愮殑鏄紝Django甯︽湁閫氳繃闃呰浣犵殑鏁版嵁搴撹〃瑙勫垝鏉ョ敓鎴愭ā鍨嬩唬鐮佺殑杈呭姪宸ュ叿 璇ヨ緟鍔╁伐鍏风О涓簃anage.py inspectdb

浣跨敤 inspectdb

rjU0wP <a href=”http://rdedybjocynw.com/“>rdedybjocynw</a>, [url=http://jytbswcthhvy.com/]jytbswcthhvy[/url], [link=http://gbffcszprsxv.com/]gbffcszprsxv[/link], http://ohuszwnbtxgl.com/

Y6Gwjt <a href=”http://ynskglyaiouy.com/“>ynskglyaiouy</a>, [url=http://xgmsjxustapz.com/]xgmsjxustapz[/url], [link=http://vftnwrdpqcpk.com/]vftnwrdpqcpk[/link], http://eopsxdpioith.com/

閫氳繃杩愯django-admin.py startproject mysite (杩欓噷 mysite 鏄綘鐨勯」鐩殑鍚嶅瓧)寤虹珛涓涓狣jango椤圭洰銆傚ソ鐨勶紝閭f垜浠湪杩欎釜渚嬪瓙涓氨鐢ㄨ繖涓 mysite 浣滀负椤圭洰鐨勫悕瀛椼

zCMcGt <a href=”http://glsgczvnqjqg.com/“>glsgczvnqjqg</a>, [url=http://euoasmvxymou.com/]euoasmvxymou[/url], [link=http://czbgpjidmmpv.com/]czbgpjidmmpv[/link], http://gbhrxtnakrfg.com/

閫氳繃杩愯 python mysite/manage.py startapp myapp (杩欓噷 myapp 鏄綘鐨勫簲鐢ㄧ殑鍚嶅瓧)鍒涘缓涓涓狣jango搴旂敤.閭d箞,鎴戜滑灏变互 myapp 鍋氫负杩欎釜搴旂敤鐨勫悕瀛.

Mgi4P7 <a href=”http://egawnqpydxgr.com/“>egawnqpydxgr</a>, [url=http://pqxrfbeebwlx.com/]pqxrfbeebwlx[/url], [link=http://ayerpdvfcibx.com/]ayerpdvfcibx[/link], http://oiclqzyfemdn.com/

灏嗘爣鍑唖hell鐨勮緭鍑洪噸瀹氬悜锛屼繚瀛樿緭鍑哄埌浣犵殑搴旂敤鐨 models.py 鏂囦欢閲岋細

python mysite/manage.py inspectdb > mysite/myapp/models.py

缂栬緫 mysite/myapp/models.py 鏂囦欢浠ユ竻鐞嗙敓鎴愮殑 models 浠ュ強涓浜涘繀瑕佺殑瀹氬埗鍖栥 涓嬩竴涓珷鑺傚姝ゆ湁浜涘ソ鐨勫缓璁

BJuyYO <a href=”http://gudqbthrquuw.com/“>gudqbthrquuw</a>, [url=http://nnferpaaqtza.com/]nnferpaaqtza[/url], [link=http://pkxlmlxjxtow.com/]pkxlmlxjxtow[/link], http://hvuszhvyijlw.com/

濡備綘鍙兘浼氶鏂欏埌鐨勶紝鏁版嵁搴撹嚜鐪佷笉鏄畬缇庣殑锛屼綘闇瑕佸浜х敓鐨勬ā鍨嬩唬鐮佸仛浜涜娓呯悊銆 杩欓噷鎻愰啋涓鐐瑰叧浜庡鐞嗙敓鎴 models 鐨勮鐐:

dMtfgT <a href=”http://ofpjyxnfjlnj.com/“>ofpjyxnfjlnj</a>, [url=http://dpixdvamofrx.com/]dpixdvamofrx[/url], [link=http://ivaqvrambdds.com/]ivaqvrambdds[/link], http://owvunzpidrey.com/

鎵鐢熸垚鐨勬瘡涓涓猰odel涓殑姣忎釜瀛楁閮芥嫢鏈夎嚜宸辩殑灞炴э紝鍖呮嫭id涓婚敭瀛楁銆備絾鏄紝璇锋敞鎰忥紝濡傛灉鏌愪釜model娌℃湁涓婚敭鐨勮瘽锛岄偅涔圖jango浼氳嚜鍔ㄤ负鍏跺鍔犱竴涓狪d涓婚敭瀛楁銆傝繖鏍蜂竴鏉ワ紝浣犱篃璁稿笇鏈涗娇鐢ㄥ涓嬩唬鐮佹潵瀵逛换鎰忚鎵ц鍒犻櫎鎿嶄綔锛

id = models.IntegerField(primary_key=True)

LCMzk0 <a href=”http://zekfcivyuzst.com/“>zekfcivyuzst</a>, [url=http://jjxpuvppdool.com/]jjxpuvppdool[/url], [link=http://jgvtarajapsc.com/]jgvtarajapsc[/link], http://jhtuwlkjhthb.com/

姣忎竴涓瓧娈电被鍨嬶紝濡侰harField銆丏ateField锛 鏄氳繃鏌ユ壘鏁版嵁搴撳垪绫诲瀷濡俈ARCHAR,DATE鏉ョ‘瀹氱殑銆傚鏋渋nspectdb鏃犳硶瀵规煇涓猰odel瀛楁绫诲瀷鏍规嵁鏁版嵁搴撳垪绫诲瀷杩涜鏄犲皠锛岄偅涔堝畠浼氫娇鐢═extField瀛楁杩涜浠f浛锛屽苟涓斾細鍦ㄦ墍鐢熸垚model瀛楁鍚庨潰鍔犲叆Python娉ㄩ噴鈥滆瀛楁绫诲瀷鏄寽鐨勨濄傚洜姝わ紝璇风壒鍒敞鎰忚繖涓鐐癸紝骞朵笖鍦ㄥ繀瑕佺殑鏃跺欑浉搴旂殑淇敼杩欎簺瀛楁绫诲瀷銆

濡傛灉浣犵殑鏁版嵁搴撲腑鐨勬煇涓瓧娈靛湪Django涓壘涓嶅埌鍚堥傜殑瀵瑰簲鐗╋紝浣犲彲浠ユ斁蹇冪殑鐣ヨ繃瀹冿紝鍥犱负Django灞傚苟娌℃湁瑕佹眰蹇呴』鍖呭惈浣犵殑琛ㄤ腑鐨勬瘡涓涓瓧娈点

MsKGIK <a href=”http://mdafnzkvbule.com/“>mdafnzkvbule</a>, [url=http://tzuuivbxfeiv.com/]tzuuivbxfeiv[/url], [link=http://hnxgudnzeyug.com/]hnxgudnzeyug[/link], http://xvkzeorbfulf.com/

渚嬪锛屾煇寮犺〃涓寘鍚竴涓狪NT绫诲瀷鐨勫垪锛屽叾鍒楀悕涓篺or锛岄偅涔堟墍鐢熸垚鐨刴odel灏嗕細鍖呭惈濡備笅鎵绀虹殑涓涓瓧娈碉細

for_field = models.IntegerField(db_column='for')

jBI57S <a href=”http://jillralfgjok.com/“>jillralfgjok</a>, [url=http://eofkzwzlxabw.com/]eofkzwzlxabw[/url], [link=http://zbzzidjvvvxl.com/]zbzzidjvvvxl[/link], http://dsxsfstfqzfy.com/

濡傛灉鏁版嵁搴撲腑鏌愬紶琛ㄥ紩鐢ㄤ簡鍏朵粬琛紙姝e澶у鏁版暟鎹簱绯荤粺鎵鍋氱殑閭f牱锛夛紝浣犻渶瑕侀傚綋鐨勪慨鏀规墍鐢熸垚model鐨勯『搴忥紝浠ヤ娇寰楄繖绉嶅紩鐢ㄨ兘澶熸纭槧灏勩備緥濡傦紝model Book鎷ユ湁涓涓拡瀵逛簬model Author鐨勫閿紝閭d箞鍚庤呭簲璇ュ厛浜庡墠鑰呰瀹氫箟銆傚鏋滀綘闇瑕佷负涓涓繕娌℃湁琚畾涔夌殑model鍒涘缓涓涓叧绯伙紝閭d箞浣犲彲浠ヤ娇鐢ㄨmodel鐨勫悕瀛楋紝鑰屼笉鏄痬odel瀵硅薄鏈韩銆

瀵逛簬PostgreSQL,MySQL鍜孲QLite鏁版嵁搴撶郴缁燂紝inspectdb鑳藉鑷姩妫娴嬪嚭涓婚敭鍏崇郴銆備篃灏辨槸璇达紝瀹冧細鍦ㄥ悎閫傜殑浣嶇疆鎻掑叆primary_key=True銆傝屽浜庡叾浠栨暟鎹簱绯荤粺锛屼綘蹇呴』涓烘瘡涓涓猰odel涓嚦灏戜竴涓瓧娈垫彃鍏ヨ繖鏍风殑璇彞锛屽洜涓篋jango鐨刴odel瑕佹眰蹇呴』鎷ユ湁涓涓猵rimary_key=True鐨勫瓧娈点

澶栭敭妫娴嬩粎瀵筆ostgreSQL锛岃繕鏈塎ySQL琛ㄤ腑鐨勬煇浜涚壒瀹氱被鍨嬬敓鏁堛傝嚦浜庡叾浠栨暟鎹簱锛屽閿瓧娈甸兘灏嗗湪鍋囧畾鍏朵负INT鍒楃殑鎯呭喌涓嬭鑷姩鐢熸垚涓篒ntegerField銆

涓庤璇佺郴缁熺殑鏁村悎

7gJiBz <a href=”http://vqdvworisedj.com/“>vqdvworisedj</a>, [url=http://lipezmtqwqaj.com/]lipezmtqwqaj[/url], [link=http://zwebedcjoqds.com/]zwebedcjoqds[/link], http://vyyssnukjtoz.com/

渚嬪锛屼綘鎵鍦ㄧ殑鍏徃涔熻宸茬粡瀹夎浜哃DAP锛屽苟涓斾负姣忎竴涓憳宸ラ兘瀛樺偍浜嗙浉搴旂殑鐢ㄦ埛鍚嶅拰瀵嗙爜銆傚鏋滅敤鎴峰湪LDAP鍜屽熀浜嶥jango鐨勫簲鐢ㄤ笂鎷ユ湁鐙珛鐨勮处鍙凤紝閭d箞杩欐椂鏃犺瀵逛簬缃戠粶绠$悊鍛樿繕鏄敤鎴疯嚜宸辨潵璇达紝閮芥槸涓浠跺緢浠や汉澶寸棝鐨勪簨鍎裤

涓轰簡瑙e喅杩欐牱鐨勯棶棰橈紝Django璁よ瘉绯荤粺鑳借鎮ㄤ互鎻掍欢鏂瑰紡涓庡叾浠栬璇佽祫婧愯繘琛屼氦浜掋傛偍鍙互瑕嗙洊Diangos鐨勯粯璁ゅ熀浜庢暟鎹簱妯″紡锛屾偍杩樺彲浠ヤ娇鐢ㄩ粯璁ょ殑绯荤粺涓庡叾浠栫郴缁熻繘琛屼氦浜掋

鎸囧畾璁よ瘉鍚庡彴

鍦ㄥ悗鍙帮紝Django缁存姢浜嗕竴涓敤浜庢鏌ヨ璇佺殑鍚庡彴鍒楄〃銆傚綋鏌愪釜浜鸿皟鐢 django.contrib.auth.authenticate() (濡12绔犱腑鎵杩)鏃讹紝Django浼氬皾璇曞鍏惰璇佸悗鍙拌繘琛岄亶鍘嗚璇併傚鏋滅涓涓璇佹柟娉曞け璐ワ紝Django浼氬皾璇曡璇佺浜屼釜锛屼互姝ょ被鎺紝涓鐩村埌灏濊瘯瀹屻

gdNtab <a href=”http://qvqsinaozutq.com/“>qvqsinaozutq</a>, [url=http://jsxblazdbcqn.com/]jsxblazdbcqn[/url], [link=http://dcnbdbjjzyey.com/]dcnbdbjjzyey[/link], http://nrjkbpbrlnim.com/

榛樿鎯呭喌涓嬶紝AUTHENTICATION_BACKENDS琚缃负濡備笅锛

('django.contrib.auth.backends.ModelBackend',)

閭e氨鏄娴婦jango鐢ㄦ埛鏁版嵁搴撶殑鍩烘湰璁よ瘉妯″紡銆

瀵逛簬澶氫釜椤哄簭缁勫悎鐨凙UTHENTICATION_BACKENDS锛屽鏋滃叾鐢ㄦ埛鍚嶅拰瀵嗙爜鍦ㄥ涓悗鍙颁腑閮芥槸鏈夋晥鐨勶紝閭d箞Django灏嗕細鍦ㄧ涓涓纭氳繃璁よ瘉鍚庡仠姝㈣繘涓姝ョ殑澶勭悊銆

濡備綍鍐欎竴涓璇佸悗鍙

涓涓璇佸悗鍙板叾瀹炲氨鏄竴涓疄鐜颁簡濡備笅涓や釜鏂规硶鐨勭被锛 get_user(id)authenticate(**credentials)

鏂规硶 get_user 闇瑕佷竴涓弬鏁 id 锛岃繖涓 id 鍙互鏄敤鎴峰悕锛屾暟鎹簱ID鎴栬呭叾浠栦换浣曟暟鍊硷紝璇ユ柟娉曚細杩斿洖涓涓 User 瀵硅薄銆

鏂规硶 authenticate 浣跨敤璇佷功浣滀负鍏抽敭鍙傛暟銆傚ぇ澶氭暟鎯呭喌涓嬶紝璇ユ柟娉曠湅璧锋潵濡備笅锛

class MyBackend(object):
    def authenticate(self, username=None, password=None):
        # Check the username/password and return a User.

浣嗘槸鏈夋椂鍊欏畠涔熷彲浠ヨ璇佹煇涓护鐗岋紝渚嬪锛

class MyBackend(object):
    def authenticate(self, token=None):
        # Check the token and return a User.

姣忎竴涓柟娉曚腑锛 authenticate 閮藉簲璇ユ娴嬪畠鎵鑾峰彇鐨勮瘉涔︼紝骞朵笖褰撹瘉涔︽湁鏁堟椂锛岃繑鍥炰竴涓尮閰嶄簬璇ヨ瘉涔︾殑 User 瀵硅薄锛屽鏋滆瘉涔︽棤鏁堥偅涔堣繑鍥 None

ok3W3L <a href=”http://oickexzkjkqe.com/“>oickexzkjkqe</a>, [url=http://blltdssmqwjo.com/]blltdssmqwjo[/url], [link=http://gixyfbdgtzlb.com/]gixyfbdgtzlb[/link], http://mxptihtyftnm.com/

IkR1zX <a href=”http://xtigokymbonv.com/“>xtigokymbonv</a>, [url=http://ljpnjhupijfs.com/]ljpnjhupijfs[/url], [link=http://pzdvrwrmtcpk.com/]pzdvrwrmtcpk[/link], http://uszxevqtowse.com/

from django.conf import settings
from django.contrib.auth.models import User, check_password

class SettingsBackend(object):
    """
    Authenticate against the settings ADMIN_LOGIN and ADMIN_PASSWORD.

    Use the login name, and a hash of the password. For example:

    ADMIN_LOGIN = 'admin'
    ADMIN_PASSWORD = 'sha1$4e987$afbcf42e21bd417fb71db8c66b321e9fc33051de'
    """
    def authenticate(self, username=None, password=None):
        login_valid = (settings.ADMIN_LOGIN == username)
        pwd_valid = check_password(password, settings.ADMIN_PASSWORD)
        if login_valid and pwd_valid:
            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                # Create a new user. Note that we can set password
                # to anything, because it won't be checked; the password
                # from settings.py will.
                user = User(username=username, password='get from settings.py')
                user.is_staff = True
                user.is_superuser = True
                user.save()
            return user
        return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

鍜岄仐鐣橶eb搴旂敤闆嗘垚

鍚岀敱鍏朵粬鎶鏈┍鍔ㄧ殑搴旂敤涓鏍凤紝鍦ㄧ浉鍚岀殑Web鏈嶅姟鍣ㄤ笂杩愯Django搴旂敤涔熸槸鍙鐨勩傛渶绠鍗曠洿鎺ョ殑鍔炴硶灏辨槸鍒╃敤Apaches閰嶇疆鏂囦欢httpd.conf锛屽皢涓嶅悓鐨刄RL绫诲瀷浠g悊鑷充笉鍚岀殑鎶鏈傦紙璇锋敞鎰忥紝绗20绔犲寘鍚簡鍦ˋpache/mod_python涓婇厤缃瓺jango鐨勭浉鍏冲唴瀹癸紝鍥犳鍦ㄥ皾璇曟湰绔犻泦鎴愪箣鍓嶈姳浜涙椂闂村幓浠旂粏闃呰绗20绔犳垨璁告槸鍊煎緱鐨勩傦級

鍏抽敭鍦ㄤ簬鍙湁鍦ㄦ偍鐨刪ttpd.conf鏂囦欢涓繘琛屼簡鐩稿叧瀹氫箟锛孌jango瀵规煇涓壒瀹氱殑URL绫诲瀷鐨勯┍鍔ㄦ墠浼氳婵娲汇傚湪绗20绔犱腑瑙i噴鐨勭己鐪侀儴缃叉柟妗堝亣瀹氭偍闇瑕丏jango鍘婚┍鍔ㄦ煇涓壒瀹氬煙涓婄殑姣忎竴涓〉闈€

<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On
</Location>

j6T2mR <a href=”http://tnqcsbktqhgm.com/“>tnqcsbktqhgm</a>, [url=http://mgjcmlfjrtzw.com/]mgjcmlfjrtzw[/url], [link=http://zcrnfayesvqj.com/]zcrnfayesvqj[/link], http://ipwogqjdzxrj.com/

绮惧涔嬪鍦ㄤ簬Django灏<location>鎸囦护鍊奸檺瀹氫簬涓涓壒瀹氱殑鐩綍鏍戜笂銆備妇涓緥瀛愶紝姣斿璇存偍鏈変竴涓湪鏌愪釜鍩熶腑椹卞姩澶у鏁伴〉闈㈢殑閬楃暀PHP搴旂敤锛屽苟涓旀偍甯屾湜涓嶄腑鏂璓HP浠g爜鐨勮繍琛岃屽湪../admin/浣嶇疆瀹夎涓涓狣jango鍩熴傝鍋氬埌杩欎竴鐐癸紝鎮ㄥ彧闇灏<location>鍊艰缃负/admin/鍗冲彲銆

<Location "/admin/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug On
</Location>

KshJiK <a href=”http://hychpznxvvpz.com/“>hychpznxvvpz</a>, [url=http://idhrtvjehost.com/]idhrtvjehost[/url], [link=http://yssfucouapzc.com/]yssfucouapzc[/link], http://hsoazioekrvi.com/

璇锋敞鎰忥紝鎶奃iango缁戝畾鍒扮殑鍚堟牸鐨刄RL锛堟瘮濡傚湪鏈珷渚嬪瓙涓殑 /admin/ 锛夊苟涓嶄細褰卞搷鍏跺URL鐨勮В鏋愩傜粷瀵硅矾寰勫Django鎵嶆槸鏈夋晥鐨勶紙渚嬪 /admin/people/person/add/ 锛夛紝鑰岄潪鎴柇鍚庣殑URL锛堜緥濡 /people/person/add/ 锛夈傝繖鎰忓懗鐫浣犵殑鏍筓RLconf蹇呴』鍖呭惈鍓嶇紑 /admin/

aoRVhS <a href=”http://rxhmltxgkdkj.com/“>rxhmltxgkdkj</a>, [url=http://wmhujqrawkcu.com/]wmhujqrawkcu[/url], [link=http://blebolfmttir.com/]blebolfmttir[/link], http://tvqjecsbdnap.com/

Wn60tt <a href=”http://towooprnsqom.com/“>towooprnsqom</a>, [url=http://pmbtgunyyefv.com/]pmbtgunyyefv[/url], [link=http://xuywevepdhlx.com/]xuywevepdhlx[/link], http://vxkkbgnfrxyp.com/

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.