python django day 3

zqxt_views/urls.py
path('', calc_views.index, name='home'),

calc/views.py
def index(request):
return render(request, 'home.html')

calc/templates/home.html
<!DOCTYPE html>
<html>
<head>
<title>自强学堂</title>
</head>
<body>

<a href="/add/4/5/">计算 4+5</a>

</body>
</html>

url跳转,一个地址自动 跳另一个地址 

python manage.py shell
reverse('add2', args=(4,5))
reverse('add2', args=(444,555))

calc\views.py 跳转的函数
def old_add2_redirect(request, a, b):
return HttpResponseRedirect(
reverse('add2', args=(a, b))
)

urls.py
path('add/<int:a>/<int:b>/', calc_views.old_add2_redirect), #update
path('new_add/<int:a>/<int:b>/', calc_views.add2, name='add2'), #add

猜你喜欢

转载自www.cnblogs.com/LiuFengH/p/9901619.html