Django模塊模板渲染之django.shortcuts包含的函數及使用

django shortcuts渲染模板


這裏沒有單獨的使用介紹,只有這個模塊下包含的這些函數的介紹,自己記錄也歡迎大家瀏覽

from django.shortcuts import render_to_response
def render_to_response(template_name, context=None,
                       context_instance=_context_instance_undefined,
                       content_type=None, status=None, dirs=_dirs_undefined,
                       dictionary=_dictionary_undefined, using=None):
        """
	返回其內容被調用結果填充的HttpResponse
	django.template.loader.render_to_string()與傳遞的參數。
        """
from django.shortcuts import render
def render(request, template_name, context=None,
           context_instance=_context_instance_undefined,
           content_type=None, status=None, current_app=_current_app_undefined,
           dirs=_dirs_undefined, dictionary=_dictionary_undefined,
           using=None):
	"""
	返回其內容被調用結果填充的HttpResponse
	django.template.loader.render_to_string()與傳遞的參數。
	默認情況下使用請求上下文。
	"""
from django.shortcuts import redirect
def redirect(to, *args, **kwargs):
	"""
	返回一個HttpResponseRedirect通過參數到相應URL
	參數可以是:
	* 模型:模型的get_absolute_url()函數將被調用。
	* 視圖名稱,可能帶有參數:urlresolvers.reverse()將用於反向解析名稱。
	* 一個URL,它將被用於重定向位置。
	* 默認情況下,臨時重定向; permanent=True 來發布永久重定向
	"""
from django.shortcuts import _get_queryset
def _get_queryset(klass):
	"""
	從模型、管理器或QuerySet中返回一個QuerySet。爲了使get_object_or_404和get_list_or_404更加DRY(代碼不重複)。
	如果klass不是Modle、Manager或QuerySet,那麼就會產生一個ValueError。
      """
from django.shortcuts import get_object_or_404
def get_object_or_404(klass, *args, **kwargs):
	"""
	使用get()返回一個對象如果對象不存在返回Http404異常。
	klass可能是一個Model、Manager或QuerySet對象; get()查詢中使用了參數和關鍵字參數。
	注意: 就像get()一樣,如果有多個返回對象,則返回多個對象。
	"""
from django.shortcuts import get_list_or_404
def get_list_or_404(klass, *args, **kwargs):
	"""
	使用filter()返回一個對象列表,如果列表爲空則返回一個Http404異常
	klass可能是一個Model、Manager或QuerySet對象。
	filter()查詢中使用了參數和關鍵字參數。
	"""
from django.shortcuts import resolve_url
def resolve_url(to, *args, **kwargs):
	"""
	返回一個與所傳遞參數相對應的URL。
	參數可以是:
	*模型:模型的get_absolute_url()函數將被調用。
	*視圖名稱,可能帶有參數:' urlresolvers.reverse()將用於反向解析名稱。
	*一個URL,它將按原樣返回。
	"""

注意:以上內容是個人使用的隨手記錄, 就是介紹了下簡單的使用

歡迎大家來吐槽,準備好瓜子飲料礦泉水,開整!!!

---------------------------------------------------------------------------------------

搞笑:能動手就儘量別吵吵


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章