from django.shortcuts import render, redirect

from django.http import HttpResponse,HttpResponsePermanentRedirect


    • HttpResponse
        它是作用是内部传入一个字符串参数,然后发给浏览器。
    • def index_handler(request):
    •        return HttpResponse("OK")
    • renderrender方法可接收三个参数,一是request参数,二是待渲染的html模板文件,三是保存具体数据的字典参数。它的作用就是将数据填充进模板文件,最后把结果返回给浏览器。
      • def index_handler(request):
      •       return render(request, 'web/test.html', context)   或者:return render(request'web/test.html')
    • redirect接受一个URL参数,表示让浏览器跳转去指定的URL.
    • def login_action(request):
    •           return redirect('/event_manage/')      备注://这两个斜杠不要漏写,否则报错。

 

HttpResponsePermanentRedirect  与redirect都是重定向,只不过是redirect的功能更强大些。


 

相关文章:

  • 2021-07-12
  • 2021-09-02
  • 2021-07-14
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-06-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案