另一种方法是使用TemplateView:
url(r'^...$', TemplateView.as_view(template_name='registration/profile.html'), name='...'),
但是,根据direct_to_template的源码:
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), content_type=mimetype)
direct_to_template 使用 RequestContext。