django-url路径书写规范
Django-URL书写规范
views.py
#url_反向解析
def test_url(request):
return render(request,'test_url.html')
def test_url_result(request):
return HttpResponse('--------响应结果-----')
test_url.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test_url</title>
</head>
<body>
<div>
<a href="http://127.0.0.1:8000/test_url_result">绝对地址</a>
<a href="/test_url_result">带'/'相对地址1</a>
<a href="test_url_result/">不带'/'相对地址2</a>
<!-----此时的路径解析为:http://127.0.0.1:8000/test_url/test_url_result/-->
<!-----http://127.0.0.1:8000/test_url/ 为当前页面url 最后一个'/' +上当前地址组合而成--->
</div>
</body>
</html>