django甯哥敤妯℃澘璇█
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django甯哥敤妯℃澘璇█相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/lin' title='lin'>lin 澶栬 home nothing als 娉ㄦ剰 鍙栧嚭 鍛婅瘔 灞曠ず
杩囨护鍣紙Filters锛?/span>
filters鏉ユ敼鍙樺彉閲忔渶缁堟樉绀虹殑鍊笺€?/span>
杩囨护鍣ㄥ氨鍍忚繖鏍穥 name|lower 銆傝繖鏄皢name鍙橀噺閫氳繃lower
杩囨护鍣ㄥ叏閮ㄨ浆鎹负灏忓啓瀛楁瘝銆?code>|鐢ㄦ潵璋冪敤杩囨护鍣ㄣ€?/p>
杩囨护鍣ㄥ彲浠ユ槸閾惧紡鐨勶紝涓€涓繃婊ゅ櫒鐨勮緭鍑轰細琚敤鍦ㄤ笅涓€涓€倇 text|escape|linebreaks 鏄竴绉嶉€氱敤鐨勫舰寮忕敤鏉ュ皢鏂囨湰鍐呭杞箟锛岀劧鍚庡啀杞负<P>鏍囩浠ラ€傜敤HTML銆?/p>
鏈変簺杩囨护鍣ㄥ甫鍙傛暟銆備緥濡備互涓嬪甫鍙傝繃婊ゅ櫒锛歿 bio|truncatewords:30 鎰忔€濇槸鍙睍绀篵io鍙橀噺鐨勫墠30涓瓧绗︺€?/p>
濡傛灉杩囨护鍣ㄥ弬鏁板惈鏈夌┖鏍奸偅涔堝弬鏁板繀椤昏寮曞彿寮曡捣鏉ワ紱姣斿鎯宠鐢ㄩ€楀彿鍜岀┖鏍煎皢list涓殑鍏冪礌鎷兼帴璧锋潵锛屽彲浠ヨ繖鏍穥 list|join锛?ldquo;锛?”銆?/p>
default
濡傛灉涓€涓彉閲忔槸false鎴栬€呮槸绌虹殑锛岄偅涔堝畠鐨勫€煎氨鏄綘缁欑殑榛樿鍊硷紝鍚﹀垯灏辨槸鍙橀噺鏈韩鐨勫€笺€?/div>value|default:"nothing"
濡傛灉鍙橀噺value娌℃湁鎻愪緵锛屾垨鑰呮槸绌虹殑璇濓紝涓婇潰灏变細鏄剧ずnothing
銆?/span>
length
杩斿洖鍙橀噺鐨勯暱搴︺€傝繖瀵逛簬瀛楃涓插拰鍒楄〃閮借捣浣滅敤銆傛瘮濡傦細
value|length
濡傛灉 value鏄竴涓垪琛╗鈥榓鈥?鈥榖鈥?鈥榗鈥?鈥榙鈥榏,閭d箞杈撳嚭灏辨槸4銆?/span>
filesizeformat
灏嗘枃浠跺ぇ灏忚浆鎹负绗﹀悎浜轰滑闃呰涔犳儻鐨勬牸寮忥紙濡傦細‘13 KB’锛?lsquo;4.1 MB’锛?lsquo;102 bytes’绛夛級
value|filesizeformat
濡傛灉value鏄?23456789鐨勮瘽锛岄偅涔堣緭鍑哄皢浼氭槸117.7MB銆?/span>
鏍囩
for
寰幆閬嶅巻鏁扮粍鎴栧垪琛紝姣斿灞曠ず鍚嶄负class_list鐨勭彮绾у垪琛細
<ul> % for class in class_list % <li> class.name </li> % endfor % </ul>
if,elif,else
% if mark >90 %
grade : 鈥樹紭绉€鈥?
% elif 60<mark<90 %
grade : 鈥樺強鏍尖€?
% else %
grade : 鈥樹笉鍙婃牸鈥?
% endif %
娉ㄦ剰% if ***** %瑕佷互% endif %鏉ョ粨鏉?/p>
妯℃澘缁ф壙
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="style.css" /> <title>% block title %My amazing site% endblock %</title> </head> <body> <div id="sidebar"> % block sidebar % <ul> <li><a href="/">Home</a></li> <li><a href="/blog/">Blog</a></li> </ul> % endblock % </div> <div id="content"> % block content %% endblock % </div> </body> </html>
杩欎釜妯℃澘鎴戜滑灏嗗畠鍙栧悕涓篵ase.html锛屽畾涔変簡涓€涓畝鍗曠殑HTML楠ㄦ灦鏂囨。锛屽湪涓€涓畝鍗曠殑涓ゅ垪甯冨眬鐨勯〉闈綘涔熻浼氱敤鍒板畠銆傚瓙妯℃澘瑕佸仛鐨勫氨鏄皢鍐呭濉厖鍒扮┖鐨勫尯鍧椾腑銆?/p>
鍦ㄨ繖涓緥瀛愪腑锛屾爣绛綽lock瀹氫箟浜嗕笁涓彲浠ヨ瀛愭ā鏉块噸鍐欑殑鍖哄潡銆傛瘡涓猙lock鏍囩閮戒細鍛婅瘔妯℃澘寮曟搸锛屽瓙妯℃澘鍙兘浼氶噸鍐欒鍖哄潡銆?/p>
涓嬮潰鎴戜滑瀹氫箟浜嗕竴涓瓙妯℃澘锛?/p>
% extends "base.html" % % block title %My amazing blog% endblock % % block content % % for entry in blog_entries % <h2> entry.title </h2> <p> entry.body </p> % endfor % % endblock %
鍏朵腑鍏抽敭鐨勫湴鏂规槸extends鏍囩锛岃繖鍙互鍛婅瘔妯℃澘寮曟搸璇ユā鏉挎槸缁ф壙浜庡叾浠栨ā鏉裤€傝繖鏍峰綋妯℃澘绯荤粺鎵ц璇ユā鏉挎椂锛屽氨鍙互鍏堝畾浣嶄粬鐨勭埗妯℃澘锛屼笂闈㈡ā鏉跨殑鐖舵ā鏉垮氨鏄?ldquo;base.html”銆?/p>
鍦ㄨ渚嬩腑锛屾ā鏉垮紩鎿庝細娉ㄦ剰鍒板湪base.html涓湁涓変釜block鏍囩锛岀劧鍚庝細灏嗗瓙妯℃澘鐨勫唴瀹瑰~鍏呭埌鐖舵ā鏉跨浉搴旂殑鍖哄潡涓€傛渶鍚庣殑缁撴灉濡備笅锛坽% block content %鍖哄潡閲屽叿浣撶殑鍐呭鏄敱blog_entries 鍙橀噺鍐冲畾鐨勶級锛?/p>
<title>My amazing blog</title> </head> <body> <div id="sidebar"> <ul> <li><a href="/">Home</a></li> <li><a href="/blog/">Blog</a></li> </ul> </div> <div id="content"> <h2>Entry one</h2> <p>This is my first entry.</p> <h2>Entry two</h2> <p>This is my second entry.</p> </div> </body> </html>
浣犲彲浠ユ牴鎹渶瑕侀噰鐢ㄥ灞傜户鎵匡紝涓€鑸潵璁叉垜浠噰鐢ㄧ殑鏄笁灞傜户鎵匡細
- 棣栧厛鍒涘缓涓€涓寘鍚綉绔欎富浣撳瑙傜殑鍩虹妯℃澘
base.html
- 涓烘瘡閮ㄥ垎鐨勭綉椤靛垱寤哄悕涓?code>base_閮ㄥ垎鍚嶇О.html鐨勬ā鏉匡紝姣斿锛宐ase_news.html锛宐ase_sports.html銆傝繖浜涙ā鏉块兘鏄户鎵縝ase.html妯℃澘锛屽苟涓旈兘鏈夎嚜宸辩殑璁捐鏍峰紡銆?/li>
- 涓烘瘡涓€绉嶇被鍨嬬殑缃戦〉鍒涘缓涓€у寲妯℃澘锛屾瘮濡傛柊闂绘垨鑰呭崥瀹紝瀹冧滑閮芥槸缁ф壙涓婅堪鐩稿簲鐨勯儴鍒嗘ā鏉?/li>
- 濡傛灉浣犺鍦ㄦā鏉挎爣绛句腑浣跨敤
% extends %
,閭d箞瀹冨繀椤讳綔涓虹涓€涓ā鏉挎爣绛撅紝鍚﹀垯妯℃澘缁ф壙灏嗗け鏁堛€?/li> - 鍦ㄤ綘鐨勫熀纭€妯℃澘涓浣跨敤
% block %
銆傝浣忥紝鍦ㄥ瓙妯℃澘涓笉涓€瀹氶兘瑕侀噸鍐欑埗妯℃澘鐨刡lock鏍囩锛屾墍浠ヤ綘鍙互鍦ㄧ埗妯℃澘涓瀹氫箟浜沚lock锛屽湪閲岄潰濉厖鍚堢悊鐨勯粯璁ゅ€硷紝杩欐牱鍦ㄥ瓙妯℃澘涓綘鍙互鏍规嵁闇€瑕侀噸鍐欑浉搴旂殑block锛屽叾浠栫殑浣跨敤鐖舵ā鏉跨殑榛樿鍊煎氨鍙互浜?/li> - 濡傛灉浣犲彂鐜板湪寰堝妯℃澘涓湁鐩稿悓鐨勫唴瀹癸紝閭d箞浣犲彲浠ュ皢杩欎簺鐩稿悓鐨勫唴瀹规彁鍙栧嚭鏉ユ斁鍦ㄧ埗妯℃澘鐨刡lock涓€?/li>
- 濡傛灉浣犳兂鑾峰彇鐖舵ā鏉縝lock涓殑鍐呭锛屼綘鍙互浣跨敤鍙橀噺 block.super 銆傚鏋滀綘鎯宠澧炲姞鐖舵ā鏉縝lock鐨勫唴瀹癸紝鑰屼笉鏄噸鍐欏畠锛岄偅涔堣繖涓彉閲忓皢浼氶潪甯告湁鐢ㄣ€備娇鐢ㄨ鍙橀噺鎻掑叆鐨勬暟鎹笉浼氳鑷姩杞箟锛堜笅闈細鎻愬埌锛夛紝鍥犱负濡傛灉鏈夊繀瑕佺殑璇濆畠宸茬粡鍦ㄧ埗妯℃澘涓杞互浜嗐€?/li>
- 鍦▄ % block % 鏍囩澶栭潰鐢?code>as鏍囩鍒涘缓鐨勫彉閲忔槸鏃犳硶鍦▄ % block % 鍐呴儴浣跨敤鐨勶紝
以上是关于django甯哥敤妯℃澘璇█的主要内容,如果未能解决你的问题,请参考以下文章