資源簡介
Django是一個開放源代碼的Web應(yīng)用框架,由Python寫成。采用了MVC的軟件設(shè)計模式,即模型M,視圖V和控制器C。Django 框架的核心組件有: 1. 用于創(chuàng)建模型的對象關(guān)系映射 2. 為最終用戶設(shè)計的完美管理界面 3. 一流的 URL 設(shè)計 4. 設(shè)計者友好的模板語言 5. 緩存系統(tǒng)。 在Django中,控制器接受用戶輸入的部分由框架自行處理,所以 Django 里更關(guān)注的是模型(Model)、模板(Template)和視圖(Views),稱為 MTV模式。它們
各自的職責(zé)如下,Django 視圖不處理用戶輸入,而僅僅決定要展現(xiàn)哪些數(shù)據(jù)給用戶,而Django 模板 僅僅決定如何展現(xiàn)Django視圖指定的數(shù)據(jù)。或者說, Django將MVC中的視圖進一步分解為 Django視圖 和 Django模板兩個部分,分別決定 “展現(xiàn)哪些數(shù)據(jù)” 和 “如何展現(xiàn)”,使得Django的模板可以根據(jù)需要隨時替換,而不僅僅限制于內(nèi)置的模板。 至于MVC控制器部分,由Django框架的URLconf來實現(xiàn)。URLconf機制是使用正則表達式匹配URL,然后調(diào)用合適的Python函數(shù)。框架把控制層給封裝了,無非與數(shù)據(jù)交互這層都是數(shù)據(jù)庫表的讀,寫,刪除,更新的操作

代碼片段和文件信息
#!/usr/bin/env?python
#?encoding:?utf-8
“““
datastore_cache.py
Created?by?Alkis?Evlogimenos?on?2009-04-19.
“““
import?itertools
import?logging
import?threading
from?google.appengine.api?import?memcache
from?google.appengine.api?import?apiproxy_stub_map
from?google.appengine.datastore?import?datastore_pb
“““Provides?a?shim?that?caches?datastore?Get?calls.
Example?code:
import?datastore_cache
datastore_cache.DatastoreCachingShim.Install()
#?...
def?main(args):
??util.run_wsgi_app(application)
??datastore_cache.DatastoreCachingShim.ResetCache()
“““
class?APIProxyShim(object):
??“““A?generic?shim?class?with?methods?to?install/uninstall?it.
??Subclasses?of?this?class?can?be?used?to?replace?the?real?stub?for?a?service
??intercepting?and?possibly?passing?on?calls?to?the?original?stub.
??“““
??SERVICE_NAME?=?None?#?To?be?overridden?by?subclasses
??_instance?=?None
??def?__init__(self?wrapped_stub):
????“““Constructor.?Internal?use?only?-?see?Install().“““
????self._wrapped_stub?=?wrapped_stub
??def?CallWrappedStub(self?call?request?response):
????“““Allows?subclasses?to?call?the?wrapped?stub.“““
????self._wrapped_stub.MakeSyncCall(self.SERVICE_NAME?call?request?response)
??def?MakeSyncCall(self?service?call?request?response):
????assert?(service?==?self.SERVICE_NAME
????????????‘Got?service?name?“%s“?expected?“%s“‘
????????????%?(service?self.SERVICE_NAME))
????messages?=?[]
????assert?request.IsInitialized(messages)?messages
????method?=?getattr(self?‘_Dynamic_‘?+?call?None)
????if?method:
??????method(request?response)
????else:
??????self.CallWrappedStub(call?request?response)
????assert?response.IsInitialized(messages)?messages
??def?__getattr__(self?name):
????“““Pass-through?to?the?wrapped?stub.“““
????return?getattr(self._wrapped_stub?name)
??@classmethod
??def?Install(cls):
????“““Installs?the?shim.?Only?needs?to?be?run?once?at?import?time.
????Note?that?this?accesses?internal?members?of?APIProxyStubMap?so?may?break
????in?future.
????“““
????if?not?cls._instance:
??????wrapped_stub?=?apiproxy_stub_map.apiproxy.GetStub(cls.SERVICE_NAME)
??????assert?wrapped_stub?“No?service?‘%s‘?found?to?wrap.“?%?cls.SERVICE_NAME
??????cls._instance?=?cls(wrapped_stub)
??????stub_dict?=?apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map
??????stub_dict[cls.SERVICE_NAME]?=?cls._instance
??@classmethod
??def?Uninstall(cls):
????“““Uninstalls?the?shim.
????Note?that?there‘s?no?need?to?uninstall?a?shim?after?each?request.?You?can
????install?it?once?at?import?time?and?leave?it?there?between?requests.
????“““
????if?cls._instance:
??????stub_dict?=?apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map
??????stub_dict[cls.SERVICE_NAME]?=?cls._instance._wrapped_stub
??????cls._instance?=?None
class?DatastoreCachingShim(APIProxyShim):
??SERVICE_NAME?=?‘datastore_v3‘
??def?__init__(self?default_stub):
????super(DatastoreCachingShim?self).__init__(default_stub)
????self.local?=?threading.local()
????self.local.to_delete?=?d
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-08-24?17:27??pLite\
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\
?????文件??????????57??2010-02-03?21:48??pLite\.hg\00changelog.i
?????文件????????9896??2010-02-03?22:36??pLite\.hg\dirstate
?????文件??????????23??2010-02-03?21:48??pLite\.hg\requires
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\
?????文件????????1169??2010-02-03?22:36??pLite\.hg\store\00changelog.i
?????文件????????6645??2010-02-03?22:36??pLite\.hg\store\00manifest.i
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\
?????文件?????????278??2010-02-03?22:36??pLite\.hg\store\data\app.yaml.i
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\appengine__django\
?????文件????????7359??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\____init____.py.i
?????文件????????8866??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\____init____.pyc.i
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\appengine__django\auth\
?????文件?????????580??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\____init____.py.i
?????文件?????????664??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\decorators.py.i
?????文件?????????682??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\middleware.py.i
?????文件????????1938??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\models.py.i
?????文件?????????974??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\templatetags.py.i
?????文件?????????718??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\auth\tests.py.i
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\appengine__django\conf\
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\appengine__django\conf\app__template\
?????文件??????????64??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\conf\app__template\____init____.py.i
?????文件?????????156??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\conf\app__template\models.py.i
?????文件??????????91??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\conf\app__template\views.py.i
?????目錄???????????0??2017-08-24?17:27??pLite\.hg\store\data\appengine__django\db\
?????文件?????????572??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\db\____init____.py.i
?????文件?????????209??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\db\____init____.pyc.i
?????文件????????1782??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\db\ba
?????文件????????2353??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\db\ba
?????文件?????????734??2010-02-03?22:36??pLite\.hg\store\data\appengine__django\db\creation.py.i
............此處省略421個文件信息
評論
共有 條評論