render
def my_view(request):# View code here...
t = loader.get_template('myapp/index.html')
c = RequestContext(request, {'foo': 'bar'})
return HttpResponse(t.render(c),content_type="application/xhtml+xml")
这就是使用 Django 模板系统的基本规则: 写模板,建立 Template 对象,建立 Context , 调用 render() 方法html
redirect
return redirect('/index/') 效果一样
response = HttpResponse("Here's the text of the Web page.")
:
will create a new HttpResponse
object with HTTP code 200 (OK), and the content passed to the constructor. In general, you should only use this for really small responses (like an AJAX form return value, if its really simple - just a number or so).前端
HttpResponseRedirect("http://example.com/")
:
will create a new HttpResponse
object with HTTP code 302 (Found/Moved temporarily). This should be used only to redirect to another pageweb
Renders a given template with a given context dictionary and returns an HttpResponse object with that rendered text.django
httpresponse render_to_response与render返回数据给前端页面,通常返回html(模板)给前端,也能够返回其余数据