url别名

  • url别名的使用  "{% url 'login_alias' %}"

========urls.py========

from django.conf.urls import include, url
from app01 import views

urlpatterns = [
    url(r'^login/$', views.login, name='login_alias'),
]

 

========views.py========

def login(request):
    if request.method == 'POST':
        name = request.POST.get('username')
        pwd = request.POST.get('pwd')
        return HttpResponse('login success!')

    return render(request, 'login.html')

 

========login.html========

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action="/login/" method="post">
    <input type="text" name="username">
    <input type="password" name="pwd">
    <input type="submit" value="submit">
</form>
</body>
</html>

 ========login.html========

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form action="{% url 'login_alias' %}" method="post">
    <input type="text" name="username">
    <input type="password" name="pwd">
    <input type="submit" value="submit">
</form>
</body>
</html>

 

posted @ 2018-09-19 13:48  运维00001  阅读(431)  评论(0编辑  收藏  举报