一、index.html编写
继续上次写我们的index
<%inherit file="base.html" />
<%def name="content()">
<h1>欢迎来到我的django练习</h1>
</%def>
<%def name="title()">首页</%def>
<%def name="css()">
<style>
h1 {
margin: 3%;
}
</style>
</%def>
展现内容就是这样。
二、登录页编写
在dashboard的views里面再建一个auth.py。
然后写一下基本内容:
# coding:utf-8
from django.views import View
from app.libs.base_render import render_to_response
class Login(View):
TEMPLATE = 'dashboard/auth/login.html'
def get(self, request):
return render_to_response(request, self.TEMPLATE)
def post(self, request):
pass
配置路由,在app/dashaboard/urls.py中:
from .views.auth import Login
urlpatterns = [
path('', Index.as_view()),
path('login', Login.as_view(), name='dashboard_login')
]
再在templates/dashboard下建一个auth文件夹,在里面新建一个login的HTML。这个login是不依赖base模板的
验证一下能否正常渲染login,成功后继续写login页面。
依旧是去bootstrap里找到表单,然后改写:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
<link href