##
通过urls路由到视图函数views下面的login(),返回html文件
urls.py
from django.contrib import admin
from django.urls import path
from CMDB import views
urlpatterns = [
path(‘admin/‘, admin.site.urls),
path(‘login/‘, views.login),
]
##
views.py
from django.shortcuts import render
from django.shortcuts import HttpResponse
# Create your views here.
def login(request):
return render(request,‘login.html‘)
def cmdb(request):
return HttpResponse(‘CMDB‘)
##
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
label{
width: 80px;
text-align: right;
display:inline-block ;
}
</style>
<body>
<form action="/login" method="post">
<p>
<label for="username">用户名:</label>
<input id="username" type="text" />
</p>
<p>
<label for="password">密码:</label>
<input id="password" type="text" />
<input type="submit" value="提交"/>
</p>
</form>
</body>
</html>
##