django-HttpResponse,render,redirect

1. Import corresponding package

from django.shortcuts import HttpResponse, render, redirect

2.HttpResponse (Returns a string to the browser)

DEF index (Request):
     # business logic code 
    return the HttpResponse ( " the OK " )

3.render (background data may be passed to the distal end, three parameters: request, url, context)

DEF index (Request):
     # business logic code 
    context = { ' username ' : ' xiximayou ' ,}
     return the render (Request, " index.html " , context = context)

3.redirect (jump to the specified url)

DEF index (Request):
     # business logic code 
    return the redirect ( " www.baidu.com " )

Mainly use render.

Guess you like

Origin www.cnblogs.com/xiximayou/p/11777068.html