开发工具:Pycharm
数据库:mysql
1、打开Pycharm软件,通过File->New Project->Django创建Django项目,填写应用名称同时创建应用;
2、运行项目后,在浏览器输入http://127.0.0.1:8000/访问;
3、templates目录下新建index.html文件,代码如下:
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>登录管理title>
<meta name="description" content="登录界面">
<meta name="keywords" content="登录界面">
<link href="" rel="stylesheet">
<style>
body,p,div,ul,li,h1,h2,h3,h4,h5,h6{
margin:0;
padding: 0;
}
body{
background: #E9E9E9;
}
#login{
width: 400px;
height: 250px;
background: #FFF;
margin:200px auto;
position: relative;
}
#login h1{
text-align:center;
position:absolute;
left:120px;
top:-40px;
font-size:21px;
}
#login form p{
text-align: center;
}
#user{
background:rgba(0,0,0,.1) no-repeat;
width: 200px;
height: 30px;
border:solid #ccc 1px;
border-radius: 3px;
padding-left: 32px;
margin-top: 50px;
margin-bottom: 30px;
}
#pwd{
background: rgba(0,0,0,.1) no-repeat;
width: 200px;
height: 30px;
border:solid #ccc 1px;
border-radius: 3px;
padding-left: 32px;
margin-bottom: 30px;
}
#submit{
width: 232px;
height: 30px;
background: rgba(0,0,0,.1);
border:solid #ccc 1px;
border-radius: 3px;
}
#submit:hover{
cursor: pointer;
background:#D8D8D8;
}
style>
head>
<body>
<div id="login">
<h1>登录管理h1>
<form action="" method="post">
<p><input type="text" name="user" id="user" placeholder="用户名">p>
<p><input type="password" name="passw0rd" id="pwd" placeholder="密码">p>
<p><input type="submit" id="submit" value="登录">p>
form>
div>
body>
html>
4、在views.py文件中定义index动作,添加代码如下:
def index(request):
return render(request, "index.html")
5、在urls.py文件中添加index的url,添加代码如下:
path('', views.index),
path('index/', views.index)