小白必会三板斧
1.HttpResponse
#返回字符串
return HttpResponse("Hello, world.")
2.render
# 返回一个模板
return render(request, 'hello.html')
# 传参返回
l1 = ['Billy', 'Felix', 'Mary']
return render(request, 'hello.html', {'l1':l1})
# hello,html 使用模板语法
{{ l1 }}
# 也可以下面这个调用<br>
{% for l in l1 %}
{{ l }}
{% endfor %}
3.redirect
# 重定向
return redirect('https:www.baidu.com')
view 视图函数为:
from django.shortcuts import render, HttpResponse, redirect
# Create your views here.
def index(request):
# return HttpResponse("Hello, world. You're at the index.html page.")
l1 = ['Billy', 'Felix', 'Mary']
return render(request, 'hello.html', {'l1': l1})
# return redirect('https:www.baidu.com')
def login(request):
return HttpResponse("login")