django HttpResponse render redirect用法

  1. 在view模块中导入

     from django.shortcuts import render,redirect, HttpResponse	
    
  2. HttpResponse
    传入一个字符串,返回给浏览器

     	def index (request):
     		return HttpResponse('Hell Django!')
    
  3. render
    可以传递三个参数 request参数,需要渲染的模板template(html参数),向模板传递的参数context

     	def index(request):
     		return render(request,'index.hrml',{'error':'this is a error message'})
    

4.redirect
接受一个URL参数,表示让浏览器跳转去指定的URL

	def index(request):
		return redirct('www.baidu.com')
原文地址:https://www.cnblogs.com/lsz-lsc/p/15194102.html