99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀Python的Django框架中TEMPLATES項的設(shè)置教程
Python的Django框架中TEMPLATES項的設(shè)置教程
2017-08-04
收藏

Python的Django框架中TEMPLATES項的設(shè)置教程

這篇文章主要介紹了Python的Django框架中TEMPLATES項的設(shè)置教程,主要針對Django1.8后的新特性,需要的朋友可以參考下.TEMPLATES

Django 1.8的新特性

一個列表,包含所有在Django中使用的模板引擎的設(shè)置。列表中的每一項都是一個字典,包含某個引擎的選項。

以下是一個簡單的設(shè)定,告訴Django模板引擎從已安裝的應(yīng)用程序(installed applications)的templates子目錄中讀取模板:    
TEMPLATES = [
  {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'APP_DIRS': True,
  },
]
以下選項對所有引擎(backends)都可用。
BACKEND
默認:無定義
使用的模板引擎。內(nèi)建的模板引擎有:   
'django.template.backends.django.DjangoTemplates'
'django.template.backends.jinja2.Jinja2'

通過設(shè)置BACKEND為一個完整的(fully-qualified)路徑(例如'mypackage.whatever.Backend'),你可以使用非Django自帶的引擎。
NAME
默認:看下面
該模板引擎的別名。它是一個標(biāo)識符,讓你在渲染時可以選擇一個引擎。別名在所有配置好的模板引擎中必須是唯一的。
當(dāng)未提供值時,默認是定義引擎類的模板名,也即是與BACKEND相鄰的最后一部分。
例如如果引擎是'mypackage.whatever.Backend',那么它的默認名為'whatever'。
DIRS
默認:[](空列表)
引擎用于查找模板源文件的目錄,按搜索順序排列。
APP_DIRS
默認:False
引擎是否在已安裝應(yīng)用程序(的目錄)內(nèi)查找模板源文件。
OPTIONS
默認:{}(空字典)
傳遞給該模板引擎(backend)的其他參數(shù)。不同的引擎,可用的參數(shù)不一樣。
TEMPLATE_CONTEXT_PROCESSORS
默認:
    
("django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages")
    在一個DjangoTemplates引擎中的OPTIONS設(shè)置'context_processors'選項來代替。

用于填充在RequestContext中的上下文的調(diào)用函數(shù)(callables)的元組。這些函數(shù)獲取一個request對象作為它的參數(shù),返回一個將要填充至上下文項目的字典。
        Django 1.8的變化:
        在Django 1.8中,內(nèi)建模板的上下文處理器從django.core.context_processors移至django.template.context_processors。
TEMPLATE_DEBUG
默認:False
        在一個DjangoTemplates引擎中的OPTIONS設(shè)置'debug' 選項來代替。

一個打開/關(guān)閉模板調(diào)試模式的布爾值。如果值是True,在模板渲染期間,拋出任何異常都將顯示一個可愛的、詳情報告的錯誤頁面。該頁面包含該模板相關(guān)的代碼段,并且使用適當(dāng)?shù)男懈吡痢?br /> 注意如果DEBUG是True,Django只會顯示可愛的錯誤頁面。
參見 DEBUG。
TEMPLATE_DIRS

默認:()(空列表)
        在一個DjangoTemplates引擎中設(shè)置'DIRS'選項來代替。

django.template.loaders.filesystem.Loader搜索模板源代碼的路徑列表,,按搜索順序排列。
注意即使在Windows中,這些路徑也是使用Unix風(fēng)格的正斜杠。
參見 The Django template language 。
TEMPLATE_LOADERS
默認:
('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')
        在一個DjangoTemplates引擎中的OPTIONS設(shè)置'loader'選項來代替。

模板讀取器類的元組,用字符串指定。每個讀取器類知道怎樣從一個特定源(particular source)中導(dǎo)入模板??蛇x地,也可以使用一個元組來代替使用一個字符串。元組中的第一項應(yīng)該是讀取器的模塊,隨后的項是在初始化時傳遞給讀取器。參見 The Django template language: for Python programmers。
TEMPLATE_STRING_IF_INVALID

默認:''(空字符串)
        在一個DjangoTemplates引擎中的OPTIONS設(shè)置'string_if_invalid' 選項來代替。

當(dāng)使用了不可用的(比如說拼寫錯誤)變量時模板系統(tǒng)輸出的字符串。參見 How invalid variables are handled。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務(wù)器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }