django中的视图层

Python71

1.什么是视图层

简单地说,它用于接收来自路由层的请求,并将相应的响应返回给浏览器

[En]

To put it simply, it is used to receive the request from the routing layer and return the corresponding response to the browser

2.视图层的格式与参数说明

2.1基本格式

from django.http import HttpResponse
def page_2003(request):
    html = '<h1>&#x7B2C;&#x4E00;&#x4E2A;&#x7F51;&#x9875;</h1>'
    return HttpResponse(html)
# &#x6CE8;&#x610F;&#x9700;&#x8981;&#x5728;&#x4E3B;&#x8DEF;&#x7531;&#x6587;&#x4EF6;&#x4E2D;&#x5F15;&#x5165;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x89C6;&#x56FE;&#x51FD;&#x6570;

2.2带有转换器参数的视图函数

```
def test(request, num):

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长