ast }}</h2>
20 <h2>这是列表的一个值:{{ lt.0|add:5 }}</h2>
21 <h2>这是一个函数:{{ func|capfirst }}</h2>
22 <h2>这是一个类对象:{{ car }}</h2>
23 <h2>这是一个类对象属性:{{ car.brand }}</h2>
24 <h2>这是一个类对象方法:{{ travel|default:"nothing"|add:' haha'|title }}</h2>
25 <p>用户名:<input type="text"></p>
26 <p>密码:<input type="password"></p>
27 <p><input type="submit" value="登录"></p>
28 </form>
29 </body>
30 </html>
最后效果
4 自动转义
自动转义是将变量的一些特殊字符,比如左箭头(<)、右箭头(>)转义成html代码,这样做的目的是为了处理一些不安全的变量。
转义前 |
转义后 |
< |
< |
> |
> |
‘ |
' |
“ |
" |
& |
& |
|
|
5 静态文件的引用
- 在项目目录下创建static的目录, 为了区分开各种类型的文件分别创建css,image,js的目录.
- 在settings.py文件中添加STATICFILES_DIRS,设置静态文件目录路径,同templates。
1 STATIC_URL = '/static/'
2 STATICFILES_DIRS = [
3 os.path.join(BASE_DIR, 'static')
4 ]
- 引用
- 创建模板/templates/studentlogin.html
1 {% load static %}
2 <!DOCTYPE html>
3 <html lang="zh-CN">
4 <head>
5 <meta charset="utf-8">
6 <meta http-equiv="X-UA-Compatible" content="IE=edge">
7 <meta name="viewport" content="width=device-width, initial-scale=1">
8 <meta name="description" content="">
9 <meta name="author" content="">
10 <title>Signin Template for Bootstrap</title>
11 <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
12 <link href="{% static 'student/css/signin.css' %}" rel="stylesheet">
13 </head>
14 </html>
15 <!-- 仅有部分代码 -->
-
- 创建/static/student/css/signin.css
1 body {
2 padding-top: 40px;
3 padding-bottom: 40px;
4 background-color: #eee;
5 }
6
7 .form-signin {
8 max-width: 330px;
9 padding: 15px;
10 margin: 0 auto;
11 }
12 .form-signin .form-signin-heading,
13 .form-signin .checkbox {
14 margin-bottom: 10px;
15 }
16 .form-signin .checkbox {
17 font-weight: normal;
18 }
19 .form-signin .form-control {
20 position: relative;
21 height: auto;
22 -webkit-box-sizing: border-box;
23 -moz-box-sizing: border-box;
24 box-sizing: border-box;
25 padding: 10px;
26 font-size: 16px;
27 }
28 .form-signin .form-control:focus {
29 z-index: 2;
30 }
31 .form-signin input[type="email"] {
32 margin-bottom: -1px;
33 border-bottom-right-radius: 0;
34 border-bottom-left-radius: 0;
35 }
36 .form-signin input[type="password"] {
37 margin-bottom: 10px;
38 border-top-left-radius: 0;
39 border-top-right-radius: 0;
40 }
1 def login(request):
2 return render(request, 'student/login.html')
1 urlpatterns = [
2 path('login/', views.login),
3 ]