绗叓绔狅細绮変笣

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了绗叓绔狅細绮変笣相关的知识,希望对你有一定的参考价值。

杩欐槸涓婂浘涓叧鑱旇〃鐨勭洿鎺ョ炕璇戙€?璇锋敞鎰忥紝鎴戞病鏈夊儚鎴戜负鐢ㄦ埛鍜岀敤鎴峰姩鎬佹墍鍋氱殑閭f牱锛屽皢琛ㄥ0鏄庝负妯″瀷銆?鍥犱负杩欐槸涓€涓櫎浜嗗閿病鏈夊叾浠栨暟鎹殑杈呭姪琛紝鎵€浠ユ垜鍒涘缓瀹冪殑鏃跺€欐病鏈夊叧鑱斿埌妯″瀷绫汇€?/p>

鐜板湪鎴戝彲浠ュ湪鐢ㄦ埛琛ㄤ腑澹版槑澶氬澶氱殑鍏崇郴浜嗭細

寤虹珛鍏崇郴鐨勮繃绋嬪疄灞炰笉鏄撱€?灏卞儚鎴戜负post涓€瀵瑰鍏崇郴鎵€鍋氱殑閭f牱锛屾垜浣跨敤db.relationship鍑芥暟鏉ュ畾涔夋ā鍨嬬被涓殑鍏崇郴銆?杩欑鍏崇郴灏?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">User瀹炰緥鍏宠仈鍒板叾浠?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">User瀹炰緥锛屾墍浠ユ寜鐓ф儻渚嬶紝瀵逛簬閫氳繃杩欑鍏崇郴鍏宠仈鐨勪竴瀵圭敤鎴锋潵璇达紝宸︿晶鐢ㄦ埛鍏虫敞鍙充晶鐢ㄦ埛銆?鎴戝湪宸︿晶鐨勭敤鎴蜂腑瀹氫箟浜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed鐨勫叧绯伙紝鍥犱负褰撴垜浠庡乏渚ф煡璇㈣繖涓叧绯绘椂锛屾垜灏嗗緱鍒板凡鍏虫敞鐨勭敤鎴峰垪琛紙鍗冲彸渚х殑鍒楄〃锛夈€?璁╂垜浠€愪釜妫€鏌ヨ繖涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">db.relationship()鎵€鏈夌殑鍙傛暟锛?/p>

  • 鈥楿ser鈥?/code>鏄叧绯诲綋涓殑鍙充晶瀹炰綋锛堝皢宸︿晶瀹炰綋鐪嬫垚鏄笂绾х被锛夈€傜敱浜庤繖鏄嚜寮曠敤鍏崇郴锛屾墍浠ユ垜涓嶅緱涓嶅湪涓や晶閮戒娇鐢ㄥ悓涓€涓疄浣撱€?/li>
  • secondary 鎸囧畾浜嗙敤浜庤鍏崇郴鐨勫叧鑱旇〃锛屽氨鏄娇鐢ㄦ垜鍦ㄤ笂闈㈠畾涔夌殑followers銆?/li>
  • primaryjoin 鎸囨槑浜嗛€氳繃鍏崇郴琛ㄥ叧鑱斿埌宸︿晶瀹炰綋锛堝叧娉ㄨ€咃級鐨勬潯浠?銆傚叧绯讳腑鐨勫乏渚х殑join鏉′欢鏄叧绯昏〃涓殑follower_id瀛楁涓庤繖涓叧娉ㄨ€呯殑鐢ㄦ埛ID鍖归厤銆?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followers.c.follower_id琛ㄨ揪寮忓紩鐢ㄤ簡璇ュ叧绯昏〃涓殑follower_id鍒椼€?/li>
  • secondaryjoin 鎸囨槑浜嗛€氳繃鍏崇郴琛ㄥ叧鑱斿埌鍙充晶瀹炰綋锛堣鍏虫敞鑰咃級鐨勬潯浠?銆?杩欎釜鏉′欢涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">primaryjoin绫讳技锛屽敮涓€鐨勫尯鍒湪浜庯紝鐜板湪鎴戜娇鐢ㄥ叧绯昏〃鐨勫瓧娈电殑鏄?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed_id浜嗐€?/li>
  • backref瀹氫箟浜嗗彸渚у疄浣撳浣曡闂鍏崇郴銆傚湪宸︿晶锛屽叧绯昏鍛藉悕涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed锛屾墍浠ュ湪鍙充晶鎴戝皢浣跨敤followers鏉ヨ〃绀烘墍鏈夊乏渚х敤鎴风殑鍒楄〃锛屽嵆绮変笣鍒楄〃銆傞檮鍔犵殑lazy鍙傛暟琛ㄧず杩欎釜鏌ヨ鐨勬墽琛屾ā寮忥紝璁剧疆涓哄姩鎬佹ā寮忕殑鏌ヨ涓嶄細绔嬪嵆鎵ц锛岀洿鍒拌璋冪敤锛岃繖涔熸槸鎴戣缃敤鎴峰姩鎬佷竴瀵瑰鐨勫叧绯荤殑鏂瑰紡銆?/li>
  • lazy鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">backref涓殑lazy绫讳技锛屽彧涓嶈繃褰撳墠鐨勮繖涓槸搴旂敤浜庡乏渚у疄浣擄紝backref涓殑鏄簲鐢ㄤ簬鍙充晶瀹炰綋銆?/li>

濡傛灉鐞嗚В璧锋潵姣旇緝鍥伴毦锛屼綘涔熶笉蹇呰繃浜庢媴蹇冦€傛垜寰呬細鍎垮氨浼氬悜浣犲睍绀哄浣曞埄鐢ㄨ繖浜涘叧绯绘潵鎵ц鏌ヨ锛屼竴鍒囧氨浼氬彉寰楁竻鏅版槑浜嗐€?/p>

鏁版嵁搴撶殑鍙樻洿锛岄渶瑕佽褰曞埌涓€涓柊鐨勬暟鎹簱杩佺Щ涓細

鏌ョ湅宸插叧娉ㄧ敤鎴风殑鍔ㄦ€?/h2>

鍦ㄦ暟鎹簱涓敮鎸佺矇涓濇満鍒剁殑宸ヤ綔鍑犺繎灏惧0锛屼絾鏄垜鍗撮仐婕忎簡涓€椤归噸瑕佺殑鍔熻兘銆傚簲鐢ㄤ富椤典腑闇€瑕佸睍绀哄凡鐧诲綍鐢ㄦ埛鍏虫敞鐨勫叾浠栨墍鏈夌敤鎴风殑鍔ㄦ€侊紝鎴戦渶瑕佺敤鏁版嵁搴撴煡璇㈡潵杩斿洖杩欎簺鐢ㄦ埛鍔ㄦ€併€?/p>

鏈€鏄捐€屾槗瑙佺殑鏂规鏄厛鎵ц涓€涓煡璇互杩斿洖宸插叧娉ㄧ敤鎴风殑鍒楄〃锛屽浣犳墍鐭ワ紝鍙互浣跨敤user.followed.all()璇彞銆傜劧鍚庡姣忎釜宸插叧娉ㄧ殑鐢ㄦ埛鎵ц涓€涓煡璇㈡潵杩斿洖浠栦滑鐨勭敤鎴峰姩鎬併€傛渶鍚庡皢鎵€鏈夌敤鎴风殑鍔ㄦ€佹寜鐓ф棩鏈熸椂闂村€掑簭鍚堝苟鍒颁竴涓垪琛ㄤ腑銆傚惉璧锋潵涓嶉敊锛熷叾瀹炰笉鐒躲€?/p>

杩欑鏂规硶鏈夊嚑涓棶棰樸€?濡傛灉涓€涓敤鎴峰叧娉ㄤ簡涓€鍗冧汉锛屼細鍙戠敓浠€涔堬紵 鎴戦渶瑕佹墽琛屼竴鍗冧釜鏁版嵁搴撴煡璇㈡潵鏀堕泦鎵€鏈夌殑鐢ㄦ埛鍔ㄦ€併€?鐒跺悗鎴戦渶瑕佸悎骞跺拰鎺掑簭鍐呭瓨涓殑涓€鍗冧釜鍒楄〃銆?浣滀负绗簩涓棶棰橈紝鑰冭檻鍒板簲鐢ㄤ富椤垫渶缁堝皢瀹炵幇鍒嗛〉锛屾墍浠ュ畠涓嶄細鏄剧ず鎵€鏈夊彲鐢ㄧ殑鐢ㄦ埛鍔ㄦ€侊紝鍙兘鏄墠鍑犱釜锛屽苟鏄剧ず涓€涓摼鎺ユ潵鎻愪緵鎰熷叴瓒g殑鐢ㄦ埛鏌ョ湅鏇村鍔ㄦ€併€?濡傛灉鎴戣鎸夊畠浠殑鏃ユ湡鎺掑簭鏉ユ樉绀哄姩鎬侊紝鎴戞€庝箞鑳界煡閬撳摢浜涚敤鎴峰姩鎬佹墠鏄墍鏈夌敤鎴蜂腑鏈€鏂扮殑鍛紵闄ら潪鎴戦鍏堝緱鍒颁簡鎵€鏈夌殑鐢ㄦ埛鍔ㄦ€佸苟瀵瑰叾杩涜鎺掑簭銆?杩欏疄闄呬笂鏄竴涓碂绯曠殑瑙e喅鏂规锛屼笉鑳藉緢濂藉湴搴斿瑙勬ā鍖栥€?/p>

鐢ㄦ埛鍔ㄦ€佺殑鍚堝苟鍜屾帓搴忔搷浣滄槸鏃犳硶閬垮厤鐨勶紝浣嗘槸鍦ㄥ簲鐢ㄤ腑鎵ц浼氬鑷存晥鐜囧崄鍒嗕綆涓嬶紝 鑰岃繖绉嶅伐浣滄槸鍏崇郴鏁版嵁搴撴搮闀跨殑銆?鎴戝彲浠ヤ娇鐢ㄦ暟鎹簱鐨勭储寮曪紝鍛戒护瀹冧互鏇存湁鏁堢殑鏂瑰紡鎵ц鏌ヨ鍜屾帓搴忋€?鎵€浠ユ垜鐪熸鎯宠鎻愪緵鐨勬柟妗堟槸锛屽畾涔夋垜鎯宠寰楀埌鐨勪俊鎭潵鎵ц涓€涓暟鎹簱鏌ヨ锛岀劧鍚庤鏁版嵁搴撴壘鍑哄浣曚互鏈€鏈夋晥鐨勬柟寮忔潵鎻愬彇杩欎簺淇℃伅銆?/p>

鐪嬬湅涓嬮潰鐨勮繖涓煡璇細

杩欐槸杩勪粖涓烘鎴戝湪杩欎釜搴旂敤涓娇鐢ㄧ殑鏈€澶嶆潅鐨勬煡璇€?鎴戝皢灏濊瘯涓€姝ヤ竴姝ュ湴瑙h杩欎釜鏌ヨ銆?濡傛灉浣犵湅涓€涓嬭繖涓煡璇㈢殑缁撴瀯锛屼綘浼氭敞鎰忓埌鏈変笁涓富瑕侀儴鍒嗭紝鍒嗗埆鏄?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">join()銆?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">filter()鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">order_by()锛屼粬浠兘鏄疭QLAlchemy鏌ヨ瀵硅薄鐨勬柟娉曪細

鑱斿悎鏌ヨ

瑕佺悊瑙oin鎿嶄綔鐨勫姛鑳斤紝鎴戜滑鏉ョ湅涓€涓緥瀛愩€?鍋囪鎴戞湁涓€涓寘鍚互涓嬪唴瀹圭殑User琛細

idusername
1john
2susan
3mary
4david

涓轰簡绠€鍗曡捣瑙侊紝鎴戝彧浼氫繚鐣欑敤鎴锋ā鍨嬬殑id鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">username瀛楁浠ヤ究杩涜鏌ヨ锛屽叾浠栫殑閮界暐鍘汇€?/p>

鍋囪followers鍏崇郴琛ㄤ腑鏁版嵁琛ㄨ揪鐨勬槸鐢ㄦ埛john鍏虫敞鐢ㄦ埛susan鍜?nbsp;david锛岀敤鎴?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">susan鍏虫敞鐢ㄦ埛mary锛岀敤鎴?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">mary鍏虫敞鐢ㄦ埛david銆傝繖浜涚殑鏁版嵁濡備笅琛ㄦ墍绀猴細

follower_idfollowed_id
12
14
23
34

鏈€鍚庯紝鐢ㄦ埛鍔ㄦ€佽〃涓寘鍚簡姣忎釜鐢ㄦ埛鐨勪竴鏉″姩鎬侊細

idtextuser_id
1post from susan2
2post from mary3
3post from david4
4post from john1

杩欏紶琛ㄤ篃鐪佺暐浜嗕竴浜涗笉灞炰簬杩欎釜璁ㄨ鑼冨洿鐨勫瓧娈点€?/p>

杩欐槸鎴戜负璇ユ煡璇㈠啀娆¤璁$殑join()璋冪敤锛?/p>

鎴戝湪鐢ㄦ埛鍔ㄦ€佽〃涓婅皟鐢╦oin鎿嶄綔銆?绗竴涓弬鏁版槸followers鍏宠仈琛紝绗簩涓弬鏁版槸join鏉′欢銆?鎴戠殑杩欎釜璋冪敤琛ㄨ揪鐨勫惈涔夋槸鎴戝笇鏈涙暟鎹簱鍒涘缓涓€涓复鏃惰〃锛屽畠灏嗙敤鎴峰姩鎬佽〃鍜屽叧娉ㄨ€呰〃涓殑鏁版嵁缁撳悎鍦ㄤ竴璧枫€?鏁版嵁灏嗘牴鎹弬鏁颁紶閫掔殑鏉′欢杩涜鍚堝苟銆?/p>

鎴戜娇鐢ㄧ殑鏉′欢琛ㄧず浜唂ollowers鍏崇郴琛ㄧ殑followed_id瀛楁蹇呴』绛変簬鐢ㄦ埛鍔ㄦ€佽〃鐨?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">user_id瀛楁銆?瑕佹墽琛屾鍚堝苟锛屾暟鎹簱灏嗕粠鐢ㄦ埛鍔ㄦ€佽〃锛坖oin鐨勫乏渚э級鑾峰彇姣忔潯璁板綍锛屽苟杩藉姞followers鍏崇郴琛紙join鐨勫彸渚э級涓殑鍖归厤鏉′欢鐨勬墍鏈夎褰曘€?濡傛灉followers鍏崇郴琛ㄤ腑鏈夊涓褰曠鍚堟潯浠讹紝閭d箞鐢ㄦ埛鍔ㄦ€佹暟鎹灏嗛噸澶嶅嚭鐜般€?濡傛灉瀵逛簬涓€涓粰瀹氱殑鐢ㄦ埛鍔ㄦ€侊紝followers鍏崇郴琛ㄤ腑鍗存病鏈夊尮閰嶏紝閭d箞璇ョ敤鎴峰姩鎬佺殑璁板綍涓嶄細鍑虹幇鍦╦oin鎿嶄綔鐨勭粨鏋滀腑銆?/p>

鍒╃敤鎴戜笂闈㈠畾涔夌殑绀轰緥鏁版嵁锛屾墽琛宩oin鎿嶄綔鐨勭粨鏋滃涓嬶細

idtextuser_idfollower_idfollowed_id
1post from susan212
2post from mary323
3post from david414
3post from david434

娉ㄦ剰user_id鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed_id鍒楀湪鎵€鏈夋暟鎹涓兘鏄浉绛夌殑锛屽洜涓鸿繖鏄痡oin鏉′欢銆?鏉ヨ嚜鐢ㄦ埛john鐨勭敤鎴峰姩鎬佷笉浼氬嚭鐜板湪涓存椂琛ㄤ腑锛屽洜涓鸿鍏虫敞鍒楄〃涓病鏈夊寘鍚?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">john鐢ㄦ埛锛屾崲鍙ヨ瘽璇达紝娌℃湁浠讳綍浜哄叧娉╦ohn銆?鑰屾潵鑷?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">david鐨勭敤鎴峰姩鎬佸嚭鐜颁簡涓ゆ锛屽洜涓鸿鐢ㄦ埛鏈変袱涓矇涓濄€?/p>

铏界劧鍒涘缓浜嗚繖涓猨oin鎿嶄綔锛屼絾鍗存病鏈夊緱鍒版兂瑕佺殑缁撴灉銆傝缁х画鐪嬩笅鍘伙紝鍥犱负杩欏彧鏄洿澶х殑鏌ヨ鐨勪竴閮ㄥ垎銆?/p>

杩囨护

Join鎿嶄綔缁欎簡鎴戜竴涓墍鏈夎鍏虫敞鐢ㄦ埛鐨勭敤鎴峰姩鎬佺殑鍒楄〃锛岃繙瓒呭嚭鎴戞兂瑕佺殑閭i儴鍒嗘暟鎹€?鎴戝彧瀵硅繖涓垪琛ㄧ殑涓€涓瓙闆嗘劅鍏磋叮鈥斺€旀煇涓敤鎴峰叧娉ㄧ殑鐢ㄦ埛浠殑鍔ㄦ€侊紝鎵€浠ユ垜闇€瑕佺敤filter()鏉ュ墧闄ゆ墍鏈夋垜涓嶉渶瑕佺殑鏁版嵁銆?/p>

杩欐槸杩囨护閮ㄥ垎鐨勬煡璇㈣鍙ワ細

璇ユ煡璇㈡槸User绫荤殑涓€涓柟娉曪紝self.id琛ㄨ揪寮忔槸鎸囨垜鎰熷叴瓒g殑鐢ㄦ埛鐨処D銆?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">filter()鎸戦€変复鏃惰〃涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">follower_id鍒楃瓑浜庤繖涓狪D鐨勮锛屾崲鍙ヨ瘽璇达紝鎴戝彧淇濈暀follower(绮変笣)鏄鐢ㄦ埛鐨勬暟鎹€?/p>

鍋囧鎴戠幇鍦ㄥid涓猴紤鐨勭敤鎴?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">john鑳界湅鍒扮殑鐢ㄦ埛鍔ㄦ€佹劅鍏磋叮锛岃繖鏄粠涓存椂琛ㄨ繃婊ゅ悗鐨勭粨鏋滐細

idtextuser_idfollower_idfollowed_id
1post from susan212
3post from david414

杩欐鏄垜鎯宠鐨勭粨鏋滐紒

璇疯浣忥紝鏌ヨ鏄粠Post绫讳腑鍙戝嚭鐨勶紝鎵€浠ュ敖绠℃垜鏇剧粡寰楀埌浜嗙敱鏁版嵁搴撳垱寤虹殑涓€涓复鏃惰〃鏉ヤ綔涓烘煡璇㈢殑涓€閮ㄥ垎锛屼絾缁撴灉灏嗘槸鍖呭惈鍦ㄦ涓存椂琛ㄤ腑鐨勭敤鎴峰姩鎬侊紝 鑰屼笉浼氬瓨鍦ㄧ敱浜庢墽琛宩oin鎿嶄綔娣诲姞鐨勫叾浠栧垪銆?/p>

鎺掑簭

鏌ヨ娴佺▼鐨勬渶鍚庝竴姝ユ槸瀵圭粨鏋滆繘琛屾帓搴忋€傝繖閮ㄥ垎鐨勬煡璇㈣鍙ュ涓嬶細

鍦ㄨ繖閲岋紝鎴戣璇寸殑鏄紝鎴戝笇鏈涗娇鐢ㄧ敤鎴峰姩鎬佷骇鐢熺殑鏃堕棿鎴虫寜闄嶅簭鎺掑垪缁撴灉鍒楄〃銆傛帓搴忎箣鍚庯紝绗竴涓粨鏋滃皢鏄渶鏂扮殑鐢ㄦ埛鍔ㄦ€併€?/p>

缁勫悎鑷韩鍔ㄦ€佸拰鍏虫敞鐨勭敤鎴峰姩鎬?/h2>

鎴戝湪followed_posts()鍑芥暟涓娇鐢ㄧ殑鏌ヨ鏄潪甯告湁鐢ㄧ殑锛屼絾鏈変竴涓檺鍒讹紝浜轰滑鏈熸湜鐪嬪埌浠栦滑鑷繁鐨勫姩鎬佸寘鍚湪浠栦滑鐨勫叧娉ㄧ殑鐢ㄦ埛鍔ㄦ€佺殑鏃堕棿绾夸腑锛岃€岃鏌ヨ鍗村姏鏈夋湭閫€?/p>

鏈変袱绉嶅彲鑳界殑鏂瑰紡鏉ユ墿灞曟鏌ヨ浠ュ寘鍚敤鎴疯嚜宸辩殑鍔ㄦ€併€?鏈€鐩存埅浜嗗綋鐨勬柟娉曟槸灏嗘煡璇繚鎸佸師鏍凤紝浣嗚纭繚鎵€鏈夌敤鎴烽兘鍏虫敞浜嗕粬浠嚜宸便€?濡傛灉浣犳槸浣犺嚜宸辩殑绮変笣锛岄偅涔堜笂闈㈢殑鏌ヨ灏变細鎵惧埌浣犺嚜宸辩殑鍔ㄦ€佷互鍙婁綘鍏虫敞鐨勬墍鏈変汉鐨勫姩鎬併€?杩欑鏂规硶鐨勭己鐐规槸浼氬奖鍝嶇矇涓濈殑缁熻鏁版嵁銆?鎵€鏈変汉鐨勭矇涓濇暟閲忛兘灏嗗姞涓€锛屾墍浠ュ畠浠繀椤诲湪鏄剧ず涔嬪墠杩涜璋冩暣銆?绗簩绉嶆柟娉曟槸閫氳繃鍒涘缓绗簩涓煡璇㈣繑鍥炵敤鎴疯嚜宸辩殑鍔ㄦ€侊紝鐒跺悗浣跨敤鈥渦nion鈥濇搷浣滃皢涓や釜鏌ヨ鍚堝苟涓轰竴涓煡璇€?/p>

娣辨€濈啛铏戜箣鍚庯紝鎴戦€夋嫨浜嗙浜屼釜鏂规銆?涓嬮潰浣犲彲浠ョ湅鍒?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed_posts()鍑芥暟宸茶鎵╁睍鎴愰€氳繃鑱斿悎鏌ヨ鏉ュ苟鍏ョ敤鎴疯嚜宸辩殑鍔ㄦ€侊細

璇锋敞鎰忥紝followed鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">own鏌ヨ缁撴灉闆嗘槸鍦ㄦ帓搴忎箣鍓嶈繘琛岀殑鍚堝苟銆?/p>

瀵圭敤鎴锋ā鍨嬫墽琛屽崟鍏冩祴璇?/h2>

铏界劧鎴戜笉鎷呭績杩欎釜绋嶆樉鈥滃鏉傗€濈殑绮変笣鏈哄埗鐨勮繍琛屾槸鍚︽棤璇€?浣嗗綋鎴戠紪鍐欎妇瓒宠交閲嶇殑浠g爜鏃讹紝鎴戞媴蹇冪殑鏄垜鍦ㄥ簲鐢ㄧ殑涓嶅悓閮ㄥ垎淇敼浜嗕唬鐮佷箣鍚庯紝濡備綍纭繚鏈浠g爜灏嗘潵浼氱户缁伐浣溿€?纭繚宸茬粡缂栧啓鐨勪唬鐮佸湪灏嗘潵缁х画鏈夋晥鐨勬渶浣虫柟娉曟槸鍒涘缓涓€濂楄嚜鍔ㄥ寲娴嬭瘯锛屼綘鍙互鍦ㄦ瘡娆℃洿鏂颁唬鐮佸悗鎵ц娴嬭瘯銆?/p>

Python鍖呭惈涓€涓潪甯告湁鐢ㄧ殑unittest鍖咃紝鍙互杞绘澗缂栧啓鍜屾墽琛屽崟鍏冩祴璇曘€?璁╂垜浠潵涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">User绫讳腑鐨勭幇鏈夋柟娉曠紪鍐欎竴浜涘崟鍏冩祴璇曞苟瀛樺偍鍒?em style="box-sizing: border-box;">tests.py妯″潡锛?/p>

鎴戞坊鍔犱簡鍥涗釜鐢ㄦ埛妯″瀷鐨勬祴璇曪紝鍖呭惈瀵嗙爜鍝堝笇銆佺敤鎴峰ご鍍忓拰绮変笣鍔熻兘銆?span> setUp()鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">tearDown()鏂规硶鏄崟鍏冩祴璇曟鏋跺垎鍒湪姣忎釜娴嬭瘯涔嬪墠鍜屼箣鍚庢墽琛岀殑鐗规畩鏂规硶銆?鎴戝湪setUp()涓疄鐜颁簡涓€浜涘皬鎶€宸э紝浠ラ槻姝㈠崟鍏冩祴璇曚娇鐢ㄦ垜鐢ㄤ簬寮€鍙戠殑甯歌鏁版嵁搴撱€?閫氳繃灏嗗簲鐢ㄩ厤缃洿鏀逛负sqlite://锛屾垜鍦ㄦ祴璇曡繃绋嬩腑閫氳繃SQLAlchemy鏉ヤ娇鐢⊿QLite鍐呭瓨鏁版嵁搴撱€?span> db.create_all()鍒涘缓鎵€鏈夌殑鏁版嵁搴撹〃銆?杩欐槸浠庡ご寮€濮嬪垱寤烘暟鎹簱鐨勫揩閫熸柟娉曪紝鍦ㄦ祴璇曚腑鐩稿綋濂界敤銆?鑰屽浜庡紑鍙戠幆澧冨拰鐢熶骇鐜鐨勬暟鎹簱缁撴瀯绠$悊锛屾垜宸茬粡閫氳繃鏁版嵁搴撹縼绉荤殑鎵嬫鍚戜綘灞曠ず杩囦簡銆?/p>

浣犲彲浠ヤ娇鐢ㄤ互涓嬪懡浠よ繍琛屾暣涓祴璇曠粍浠讹細

浠庣幇鍦ㄨ捣锛屾瘡娆″搴旂敤杩涜鏇存敼鏃讹紝閮藉彲浠ラ噸鏂拌繍琛屾祴璇曪紝浠ョ‘淇濇鍦ㄦ祴璇曠殑鍔熻兘娌℃湁鍙楀埌褰卞搷銆?鍙﹀锛屾瘡娆″皢鍙︿竴涓姛鑳芥坊鍔犲埌搴旂敤鏃讹紝閮藉簲璇ヤ负鍏剁紪鍐欎竴涓崟鍏冩祴璇曘€?/p>

鍦ㄥ簲鐢ㄤ腑闆嗘垚绮変笣鏈哄埗

鏁版嵁搴撳拰妯″瀷涓矇涓濇満鍒剁殑瀹炵幇鐜板湪宸茬粡瀹屾垚锛屼絾鏄垜娌℃湁灏嗗畠闆嗘垚鍒板簲鐢ㄤ腑锛屾墍浠ユ垜鐜板湪瑕佹坊鍔犺繖涓姛鑳姐€?鍊煎緱楂樺叴鐨勬槸锛屽疄鐜板畠娌℃湁浠€涔堝ぇ鐨勬寫鎴橈紝閮藉皢鍩轰簬浣犲凡缁忓杩囩殑姒傚康銆?/p>

璁╂垜浠潵娣诲姞涓や釜鏂扮殑璺敱鍜岃鍥惧嚱鏁帮紝瀹冧滑鎻愪緵浜嗙敤鎴峰叧娉ㄥ拰鍙栨秷鍏虫敞鐨刄RL鍜岄€昏緫瀹炵幇锛?/p>

瑙嗗浘鍑芥暟鐨勯€昏緫涓嶈█鑰屽柣锛屼絾瑕佹敞鎰忔墍鏈夌殑閿欒妫€鏌ワ紝浠ラ槻姝㈠嚭鐜版剰澶栫殑闂锛屽苟灏濊瘯鍦ㄥ嚭鐜伴棶棰樻椂鍚戠敤鎴锋彁渚涙湁鐢ㄧ殑淇℃伅銆?/p>

鎴戝皢娣诲姞杩欎袱涓鍥惧嚱鏁扮殑璺敱鍒版瘡涓敤鎴风殑涓汉涓婚〉涓紝浠ヤ究鍏朵粬鐢ㄦ埛鎵ц鍏虫敞鍜屽彇娑堝叧娉ㄧ殑鎿嶄綔锛?/p>

鐢ㄦ埛涓汉涓婚〉鐨勫彉鏇达紝涓€鏄湪鏈€杩戣闂殑鏃堕棿鎴充箣涓嬫坊鍔犱竴琛岋紝浠ユ樉绀烘鐢ㄦ埛鎷ユ湁澶氬皯涓矇涓濆拰鍏虫敞鐢ㄦ埛銆備簩鏄綋浣犳煡鐪嬭嚜宸辩殑涓汉涓婚〉鏃跺嚭鐜扮殑鈥淓dit鈥濋摼鎺ョ殑琛岋紝鍙兘浼氬彉鎴愪互涓嬩笁绉嶉摼鎺ヤ箣涓€锛?/p>

  • 濡傛灉鐢ㄦ埛鏌ョ湅浠?濂?鑷繁鐨勪釜浜轰富椤碉紝浠嶇劧鏄€淓dit鈥濋摼鎺ヤ笉鍙樸€?/li>
  • 濡傛灉鐢ㄦ埛鏌ョ湅鍏朵粬骞舵湭鍏虫敞鐨勭敤鎴风殑涓汉涓婚〉锛屾樉绀衡€淔ollow鈥濋摼鎺ャ€?/li>
  • 濡傛灉鐢ㄦ埛鏌ョ湅鍏朵粬宸茬粡鍏虫敞鐨勭敤鎴风殑涓汉涓婚〉锛屾樉绀衡€淯nfollow鈥濋摼鎺ャ€?/li>

姝ゆ椂锛屼綘鍙互杩愯璇ュ簲鐢紝鍒涘缓涓€浜涚敤鎴峰苟娴嬭瘯涓€涓嬪叧娉ㄥ拰鍙栨秷鍏虫敞鐢ㄦ埛鐨勫姛鑳姐€?鍞竴闇€瑕佽浣忕殑鏄紝闇€瑕佹墜鍔ㄩ敭鍏ヤ綘瑕佸叧娉ㄦ垨鍙栨秷鍏虫敞鐨勭敤鎴风殑涓汉涓婚〉URL锛屽洜涓虹洰鍓嶆病鏈夊姙娉曟煡鐪嬬敤鎴峰垪琛ㄣ€?渚嬪锛屽鏋滀綘鎯冲叧娉?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">susan锛屽垯闇€瑕佸湪娴忚鍣ㄧ殑鍦板潃鏍忎腑杈撳叆http://localhost:5000/user/susan浠ヨ闂鐢ㄦ埛鐨勪釜浜轰富椤点€?璇风‘淇濅綘鍦ㄦ祴璇曞叧娉ㄥ拰鍙栨秷鍏虫敞鐨勬椂鍊欙紝鐣欐剰鍒颁簡鍏剁矇涓濆拰鍏虫敞鐨勬暟閲忓彉鍖栥€?/p>

鎴戝簲璇ュ湪搴旂敤鐨勪富椤典笂鏄剧ず鐢ㄦ埛鍔ㄦ€佺殑鍒楄〃锛屼絾鏄垜杩樻病鏈夊畬鎴愭墍鏈変緷璧栫殑宸ヤ綔锛屽洜涓虹敤鎴蜂笉鑳藉彂琛ㄥ姩鎬併€?鎵€浠ユ垜浼氭殏缂撹繖涓〉闈㈢殑瀹屽杽宸ヤ綔锛岀洿鍒板彂琛ㄧ敤鎴峰姩鎬佸姛鑳界殑瀹屾垚銆?/p>

以上是关于绗叓绔狅細绮変笣的主要内容,如果未能解决你的问题,请参考以下文章

璁捐妯″紡@绗?5绔狅細浠g悊妯″紡

绗笁绔狅細鍏充簬浜ゆ崲鏈虹殑鑷涔犱笌杞彂

Spring 瀹炰緥鍖栨柟寮忔湁鍑犵锛熶负浠€涔堜細鐢ㄥ埌 Cglib锛?

涓嶈閿欒繃锛孒adoop銆丼park 鏍稿績鎶€鏈爤璁茶В

鍏虫敞鍜屽彇娑堝叧娉?/h2>

鎰熻阿SQLAlchemy ORM锛屼竴涓敤鎴峰叧娉ㄥ彟涓€涓敤鎴风殑琛屼负鍙互閫氳繃followed鍏崇郴鎶借薄鎴愪竴涓垪琛ㄦ潵绠€渚夸娇鐢ㄣ€?渚嬪锛屽鏋滄垜鏈変袱涓敤鎴峰瓨鍌ㄥ湪user1鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">user2鍙橀噺涓紝鎴戝彲浠ョ敤涓嬮潰杩欎釜绠€鍗曠殑璇彞鏉ュ疄鐜帮細

瑕佸彇娑堝叧娉ㄨ鐢ㄦ埛锛屾垜鍙互杩欎箞鍋氾細

鍗充究鍏虫敞鍜屽彇娑堝叧娉ㄧ殑鎿嶄綔鐩稿綋瀹规槗锛屾垜浠嶇劧鎯虫彁楂樿繖娈典唬鐮佺殑鍙噸鐢ㄦ€э紝鎵€浠ユ垜涓嶄細鐩存帴鍦ㄤ唬鐮佷腑浣跨敤鈥渁ppends鈥濆拰鈥渞emoves鈥濓紝鍙栬€屼唬涔嬶紝鎴戝皢鍦?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">User妯″瀷涓疄鐜扳€渇ollow鈥濆拰鈥渦nfollow鈥濇柟娉曘€?鏈€濂藉皢搴旂敤閫昏緫浠庤鍥惧嚱鏁拌浆绉诲埌妯″瀷鎴栧叾浠栬緟鍔╃被鎴栬緟鍔╂ā鍧椾腑锛屽洜涓轰綘浼氬湪鏈珷涔嬪悗灏嗕細鐪嬪埌锛岃繖浣垮緱鍗曞厓娴嬭瘯鏇村姞瀹规槗銆?/p>

涓嬮潰鏄敤鎴锋ā鍨嬩腑娣诲姞鍜屽垹闄ゅ叧娉ㄥ叧绯荤殑浠g爜鍙樻洿锛?/p>

follow()鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">unfollow()鏂规硶浣跨敤鍏崇郴瀵硅薄鐨?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">append()鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">remove()鏂规硶銆傛湁蹇呰鍦ㄥ鐞嗗叧绯讳箣鍓嶏紝浣跨敤涓€涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">is_following()鏂规硶鏉ョ‘璁ゆ搷浣滅殑鍓嶆彁鏉′欢鏄惁绗﹀悎锛屼緥濡傦紝濡傛灉鎴戣姹?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">user1鍏虫敞user2锛屼絾浜嬪疄璇佹槑杩欎釜鍏崇郴鍦ㄦ暟鎹簱涓凡缁忓瓨鍦紝鎴戝氨娌″繀瑕侀噸澶嶆搷浣滀簡銆?鐩稿悓鐨勯€昏緫鍙互搴旂敤浜庡彇娑堝叧娉ㄣ€?/p>

is_following()鏂规硶鍙戝嚭涓€涓叧浜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">followed鍏崇郴鐨勬煡璇㈡潵妫€鏌ヤ袱涓敤鎴蜂箣闂寸殑鍏崇郴鏄惁宸茬粡瀛樺湪銆?浣犲凡缁忕湅鍒拌繃鎴戜娇鐢⊿QLAlchemy鏌ヨ瀵硅薄鐨?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">filter_by()鏂规硶锛屼緥濡傦紝鏌ユ壘缁欏畾鐢ㄦ埛鍚嶇殑鐢ㄦ埛銆?鎴戝湪杩欓噷浣跨敤鐨?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">filter()鏂规硶寰堢被浼硷紝浣嗘槸鏇村姞鍋忓悜搴曞眰锛屽洜涓哄畠鍙互鍖呭惈浠绘剰鐨勮繃婊ゆ潯浠讹紝鑰屼笉鍍?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">filter_by()锛屽畠鍙兘妫€鏌ユ槸鍚︾瓑浜庝竴涓父閲忓€笺€?鎴戝湪is_following()涓娇鐢ㄧ殑杩囨护鏉′欢鏄紝鏌ユ壘鍏宠仈琛ㄤ腑宸︿晶澶栭敭璁剧疆涓?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">self鐢ㄦ埛涓斿彸渚ц缃负user鍙傛暟鐨勬暟鎹銆?鏌ヨ浠?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">count()鏂规硶缁撴潫锛岃繑鍥炵粨鏋滅殑鏁伴噺銆?杩欎釜鏌ヨ鐨勭粨鏋滄槸0鎴?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">1锛屽洜姝ゆ鏌ヨ鏁版槸1杩樻槸澶т簬0瀹為檯涓婃槸鐩哥瓑鐨勩€?鑷充簬鍏朵粬鐨勬煡璇㈢粨鏉熺all()鍜?code style="box-sizing: border-box; text-align: left; border: 1px solid rgb(223, 226, 229); border-radius: 3px; padding: 2px 4px 0px; font-size: 0.9rem; background-color: rgb(248, 248, 248);">first()锛屼綘宸茬粡鐪嬪埌鎴戜娇鐢ㄨ繃浜嗐€?/p>