07 2019 档案

摘要:URL 配置: urls.py 中的基本配置: from django.conf.urls import url from app01 import views urlpatterns = [ url(正则表达式, views 视图函数[, 参数, 别名]), ] 在 Django 2 版本后将 u 阅读全文
posted @ 2019-07-31 17:21 Sch01aR# 编辑
摘要:用 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# 编辑
摘要: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# 编辑
摘要: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# 编辑
摘要: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# 编辑
摘要: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# 编辑
摘要:静态文件的路径设置在 settings.py 中 如果该路径发生更改的话,html 中相关路径也要进行修改 CSS: <link href="/static/dashboard.css" rel="stylesheet"> 可以写成: {% load static %} <link href="{% 阅读全文
posted @ 2019-07-29 19:27 Sch01aR# 编辑
摘要:网站中通常会有一个导航条,如下图 这个导航条在很多页面都会存在 可以把导航条做成一个组件,让要显示导航条的网页包含 导航条组件 nav.html: <h1>假装这是一个导航条</h1> 用 muban_test.html 来导入: <hr>{# 导入导航条组件 #} {% include 'nav. 阅读全文
posted @ 2019-07-29 18:05 Sch01aR# 编辑
摘要:可以把多个页面相同的部分提取出来,放在一个母板里,这些页面只需要继承这个母板就好了 通常会在母板中定义页面专用的 CSS 块和 JS 块,方便子页面替换 定义块: {% block 名字 %} {% endblock %} views.py 中添加函数: from django.shortcuts 阅读全文
posted @ 2019-07-29 17:21 Sch01aR# 编辑
摘要:标签使用 {% %} 注释语句:{# #} 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# 编辑
摘要:自定义过滤器的文件: 在 app01 下新建一个 templatetags 的文件夹,然后创建 myfilter.py 文件 这个 templatetags 名字是固定的,myfilter 是自己起的 myfilter.py: from django import template register 阅读全文
posted @ 2019-07-26 20:50 Sch01aR# 编辑
摘要:通过管道符 "|" 来使用过滤器,{{ value|过滤器:参数 }} Django 的模板语言中提供了六十个左右的内置过滤器 urls.py: from django.conf.urls import url from django.contrib import admin from app01 阅读全文
posted @ 2019-07-26 19:56 Sch01aR# 编辑
摘要:前言: 在 Django 模板语言中变量用 {{ }},逻辑用 {% %} 在 urls.py 中添加对应关系 from django.conf.urls import url from django.contrib import admin from app01 import views urlp 阅读全文
posted @ 2019-07-25 22:57 Sch01aR# 编辑
摘要:在作者列表页面的操作栏中加上编辑按钮 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>作者列表</title> </head> <body> <h1>作者列表</h1> <table border="1"> 阅读全文
posted @ 2019-07-24 22:39 Sch01aR# 编辑
摘要:修改 author_list.html,添加删除按钮 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>作者列表</title> </head> <body> <h1>作者列表</h1> <table bord 阅读全文
posted @ 2019-07-24 20:40 Sch01aR# 编辑
摘要:在 book_list.html 的页面下方加上 “添加作者” 的链接 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>作者列表</title> </head> <body> <h1>作者列表</h1> <t 阅读全文
posted @ 2019-07-24 20:00 Sch01aR# 编辑
摘要:在 views.py 中添加展示作者列表的函数 from django.shortcuts import render, redirect, HttpResponse from app01 import models # 展示出版社列表 def publisher_list(request): pa 阅读全文
posted @ 2019-07-24 17:10 Sch01aR# 编辑
摘要:models.py 代码: from django.db import models # Create your models here. # 出版社 class Publisher(models.Model): id = models.AutoField(primary_key=True) # 自 阅读全文
posted @ 2019-07-24 15:11 Sch01aR# 编辑
摘要:展示书籍列表: 首先修改原先的 book_list.html 的代码: <!DOCTYPE html> <!-- saved from url=(0042)https://v3.bootcss.com/examples/dashboard/ --> <html lang="zh-CN"> <head 阅读全文
posted @ 2019-07-23 22:04 Sch01aR# 编辑

点击右上角即可分享
微信分享提示