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>

 

鏍囩

鏍囩鐨勫舰寮忔槸 % tag %銆傛爣绛炬瘮鍙橀噺瑕佹洿澶嶆潅锛氭湁浜涙爣绛惧湪杈撳嚭涓垱寤烘枃鏈紝鏈変簺閫氳繃灞曠ず寰幆鍜岄€昏緫鏉ユ帶鍒舵祦锛屾湁浜涘紩鍏ラ澶栫殑淇℃伅鍒版ā鏉夸腑浠ヤ緵鍚庣画鍙橀噺浣跨敤
 

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>

 

妯℃澘缁ф壙

鍦―jango妯℃澘寮曟搸涓渶缁欏姏涔熸槸鏈€澶嶆潅鐨勯儴鍒嗗氨鏄ā鏉跨户鎵裤€傛ā鏉跨户鎵垮彲浠ヤ娇浣犲缓绔嬩竴涓寘鍚綉绔欐墍鏈夊叕鍏卞厓绱犵殑鍩烘湰楠ㄦ灦锛屽湪閲岄潰鍙互瀹氫箟涓€浜涘尯鍧楋紝妯℃澘鐨勫瓙妯℃澘鍙互閲嶅啓杩欎簺鍖哄潡銆?/div>
涓嬮潰鐨勪緥瀛愬彲浠ヨ浣犳洿濂界殑鐞嗚В妯℃澘缁ф壙锛?
<!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 % 鍐呴儴浣跨敤鐨勶紝
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€閮ㄥ垎鍐呭鎽樿嚜http://www.jianshu.com/p/1664dcfd840c
 
 
 
 

以上是关于django甯哥敤妯℃澘璇█的主要内容,如果未能解决你的问题,请参考以下文章

甯哥敤 Git 鍛戒护

abap 甯哥敤璇硶

php 甯哥敤姝e垯

GitLab 甯哥敤鍛戒护

Linux甯哥敤鍛戒护

Linux甯哥敤鍛戒护