"""S14Djngo URL Configuration The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin from cmdb import views urlpatterns = [
url(r'^admin/', admin.site.urls),
#url(r'^h.html/',views.home),
url(r'^login',views.login),
url(r'^home', views.home),
]
urls.py
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/static/commons.css"/>
<style>
label{
width:80px;
text-align:right;
display: inline-block;
}
</style>
</head>
<body> <form action="/login" method="post">
<p>
<label for="username">用户名:</label>
<input id="username" name="user" type='text'/>
</p>
<p>
<label for="password">密码:</label>
<input id="password" name="pwd" type='password'/>
<input type="submit" value="提交"/>
<span style="color:red;">{{ error_msg }}</span>
</p>
</form>
<script src ="/static/jquery.min.js"></script>
</body>
</html>
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<meta charset = "utf-8">
<title>Title</title>
<body style="margin: 0">
<div style="height: 48px;background-color: #ddb796"></div>
<div>
<table>
<tr>
<td>李杰</td>
<td>男</td>
<td>sra@126.com</td>
</tr>
<tr>
<td>研行</td>
<td>女</td>
<td>dgdg@163.com</td>
</tr>
<tr>
<td>天天</td>
<td>中</td>
<td>sfsf@139.com</td>
</tr>
</table>
</div> </body>
</html>
home.html
from django.shortcuts import render
# Create your views here. from django.shortcuts import render
from django.shortcuts import redirect #重新定向模块 def login(request):
#包含用户提交的所有信息
#获取用户提交方法
#print(request.method)
error_msg = ""
if request.method == "POST":
#获取用户通过POST提交过来的数据
user =request.POST.get('user',None)
pwd =request.POST.get('pwd',None)
if user == 'root' and pwd == '':
#去跳转到
return redirect('home.html')
else:
#用户密码不匹配
error_msg = '用户名或密码错误'
# user = request.POST['user']
# pwd = request.POST['pwd']
# print(user,pwd)
return render(request,'login.html',{'error_msg':error_msg}) def home(request):
return render(request,'home.html')
views.py
用JetBrains PyCharm 2017.2创建运行Django程序
http://www.cnblogs.com/ujq3/p/7882030.html
创建多个Django业务模块
http://www.cnblogs.com/ujq3/p/7884075.html
Django多业务模块的写法
http://www.cnblogs.com/ujq3/p/7884279.html
Django与HTML业务基本结合--基本的用户名密码提交方法2
http://www.cnblogs.com/ujq3/p/7884615.html
Django静态文件以及模板文件的配置
http://www.cnblogs.com/ujq3/p/7884881.html
Django用户名密码错误提示
http://www.cnblogs.com/ujq3/p/7891352.html