顯示登錄頁面的步驟
- 創(chuàng)建Django項目
- 在終端中創(chuàng)建應(yīng)用
python manage.py startapp name
- 在項目包
web_project/settings.py
中添加應(yīng)用
# web_project/settings.py
# Application definition
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'student'
]
- 確定訪問路徑
http://127.0.0.1:8000/student/
- 配置項目根路由
web_project/urls.py
# web_project/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('student/', include('student.urls')),
path('admin/', admin.site.urls),
]
- 應(yīng)用包下創(chuàng)建并配置
urls.py
文件
# student/urls.py
# coding = utf-8
from django.conf.urls import url
from . import views
urlpatterns = [
url('', views.login_view)
]
- 應(yīng)用包下
views.py
文件創(chuàng)建處理函數(shù)
# student/views.py
from django.shortcuts import render
# Create your views here.
def login_view(request):
return render(request, 'stu/login.html')
- 在
template/stu/
下創(chuàng)建 login.html
<html>
<body>
<form>
<p>
<label>UserName</label>
<input type="text" neme="uname">
</p>
<p>
<label>Password</label>
<input type="password" neme="pwd">
</p>
<p>
{% comment %} 空格 {% endcomment %}
   
<input type="submit" value="Login">
</p>
</form>
</body>
</html>