Django5/helloWorld/views.py
2025-04-27 22:24:46 +08:00

27 lines
905 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.http import HttpResponse
from django.shortcuts import render, redirect
# Create your views here.
def index(request):
# redirect重定向permanent为True时永久重定向
return redirect("/static/new.html", permanent=True)
#return redirect("/blog/2")
# print("页面请求处理中")
# return render(request, 'index.html')
def blog(request, id):
#输入http://localhost:8000/blog/0会跳转到http://localhost:8000/static/error.html
if id==0:
return redirect("/static/error.html")
else:
return HttpResponse("id是" + str(id) + "的博客页面")
def blog2(request, year, month, day, id):
return HttpResponse(str(year) + '/' + str(month) + '/' + str(day) + '/' + ' id是' + str(id) + "的博客页面")
def blog3(request, year, month, day):
return HttpResponse(str(year) + '/' + str(month) + '/' + str(day) + "的博客页面")