视图和装饰器-1

This commit is contained in:
2026-07-01 17:29:04 +08:00
parent 6000f3cf7b
commit fe14f65ed5
4 changed files with 46 additions and 4 deletions

10
user/test.html Normal file
View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
我的位置是真实存在的
</body>
</html>

View File

@@ -1,3 +1,7 @@
from django.contrib import admin
from django.urls import path
urlpatterns = []
from user.views import t1
urlpatterns = [
path('',t1),
]
print(urlpatterns)

View File

@@ -1,3 +1,26 @@
from django.shortcuts import render
from django.shortcuts import render
from django.http import HttpResponse,HttpRequest
# Create your views here.
def t1(resquest:HttpResponse):
print(resquest.method)
return HttpResponse('function response ok!')
content = """"
<html>
<head><title>zhibang</title></head>
<body>
我是案例2
</body>
</html>
"""
## 动态生成网页
def t2(request):
return HttpResponse(content)
## 静态网页
def t3(request):
with open(r'D:\python_project\pythonProject\user\test.html', 'rb') as f:
return HttpResponse(f.read())