上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 78 下一页
摘要: 用 json 模块和 HttpResponse 返回生成的 json views.py: from django.shortcuts import render, HttpResponse import json # json 测试 def json_test(request): data = {" 阅读全文
posted @ 2019-07-30 20:30 Sch01aR# 阅读(1943) 评论(0) 推荐(1)
摘要: request.method: 获取请求的方法,例如 GET、POST 等 views.py: from django.shortcuts import render, HttpResponse # request 对象 def test(request): print(request.method 阅读全文
posted @ 2019-07-30 18:27 Sch01aR# 阅读(1379) 评论(0) 推荐(0)
摘要: FBV: Function Base View,基于函数的视图 views.py: from django.shortcuts import render, HttpResponse # FBV def upload(request): if request.method == "POST": fi 阅读全文
posted @ 2019-07-30 17:50 Sch01aR# 阅读(266) 评论(0) 推荐(0)
摘要: upload.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>上传页面</title> </head> <body> <form action="/upload/" method="post" e 阅读全文
posted @ 2019-07-30 17:32 Sch01aR# 阅读(383) 评论(0) 推荐(0)
摘要: simple_tag: simple_tag 和自定义 filter 类似,但可以接收更多更灵活的参数 在 app01/templatetags/ 目录下创建 mysimple_tag.py mysimple_tag.py: from django import template register 阅读全文
posted @ 2019-07-29 20:51 Sch01aR# 阅读(415) 评论(0) 推荐(0)
摘要: 静态文件的路径设置在 settings.py 中 如果该路径发生更改的话,html 中相关路径也要进行修改 CSS: <link href="/static/dashboard.css" rel="stylesheet"> 可以写成: {% load static %} <link href="{% 阅读全文
posted @ 2019-07-29 19:27 Sch01aR# 阅读(216) 评论(0) 推荐(0)
摘要: 网站中通常会有一个导航条,如下图 这个导航条在很多页面都会存在 可以把导航条做成一个组件,让要显示导航条的网页包含 导航条组件 nav.html: <h1>假装这是一个导航条</h1> 用 muban_test.html 来导入: <hr>{# 导入导航条组件 #} {% include 'nav. 阅读全文
posted @ 2019-07-29 18:05 Sch01aR# 阅读(198) 评论(0) 推荐(0)
摘要: 可以把多个页面相同的部分提取出来,放在一个母板里,这些页面只需要继承这个母板就好了 通常会在母板中定义页面专用的 CSS 块和 JS 块,方便子页面替换 定义块: {% block 名字 %} {% endblock %} views.py 中添加函数: from django.shortcuts 阅读全文
posted @ 2019-07-29 17:21 Sch01aR# 阅读(424) 评论(0) 推荐(0)
摘要: 标签使用 {% %} 注释语句:{# #} for 循环: views.py: from django.shortcuts import render, redirect, HttpResponse from app01 import models # Filter 测试 def filter_te 阅读全文
posted @ 2019-07-26 21:29 Sch01aR# 阅读(269) 评论(0) 推荐(0)
摘要: 自定义过滤器的文件: 在 app01 下新建一个 templatetags 的文件夹,然后创建 myfilter.py 文件 这个 templatetags 名字是固定的,myfilter 是自己起的 myfilter.py: from django import template register 阅读全文
posted @ 2019-07-26 20:50 Sch01aR# 阅读(661) 评论(0) 推荐(0)
上一页 1 ··· 43 44 45 46 47 48 49 50 51 ··· 78 下一页