Django视图的自定义呈现函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django视图的自定义呈现函数相关的知识,希望对你有一定的参考价值。
def render(request, template, context=None): return render_to_response( template, context or {},context_instance=RequestContext(request) ) django.views.generic.simple.direct_to_template takes request as the first parameter and does the same thing, in addition to providing URL parameters. Here’s the source, from django/views/generic/simple.py: def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): """ Render a given template with any extra URL parameters in the context as ``{{ params }}``. """ if extra_context is None: extra_context = {} dictionary = {'params': kwargs} for key, value in extra_context.items(): if callable(value): dictionary[key] = value() else: dictionary[key] = value c = RequestContext(request, dictionary) t = loader.get_template(template) return HttpResponse(t.render(c), mimetype=mimetype)
以上是关于Django视图的自定义呈现函数的主要内容,如果未能解决你的问题,请参考以下文章