- 博客(399)
- 收藏
- 关注
转载 Python - Django - 命名空间模式
新建一个项目 app02在 app02/ 下创建 urls.py:from django.conf.urls import urlfrom app02 import viewsurlpatterns = [ url(r'^blog/', views.test, name="blog"),]app01/urls.py:from ...
2019-08-01 22:14:00
139
转载 Python - Django - ORM 自定义表名
通过 Django 建立的表命名方式为:项目名_表名可以将该默认命名方式进行修改models.py:from django.db import modelsclass Person(models.Model): id = models.AutoField(primary_key=True) name = models.CharFie...
2019-08-01 21:05:00
1508
转载 Python - Django - ORM 常用的字段属性
字段参数:null:用于表示某个字段可以为空unique:如果设置为 unique=True,则该字段在此表中必须是唯一的db_index:如果 db_index=True,则代表着为此字段设置数据库索引default:为该字段设置默认值关系字段参数:to:设置要关联的表to_field:设置要关联的表的字段related_name:反向操作时,使用...
2019-08-01 20:53:00
139
转载 Python - Django - ORM 自定义 char 类型字段
用 CharField 定义的字段在数据库中存放为 verchar 类型自定义 char 类型字段需要下面的代码:class FixedCharField(models.Field): """ 自定义的 char 类型的字段类 """ def __init__(self, max_length, *args, **kwargs):...
2019-08-01 20:13:00
349
转载 Python - Django - ORM 不常用字段
BigAutoField(AutoField):bigint 自增列,必须填入参数 primary_key=True如果没有写自增列,则会自动创建一个列名为 id 的列SmallIntegerField(IntegerField):短整型,-32768 到 32767PositiveSmallIntegerField(PositiveIntegerRelD...
2019-08-01 19:39:00
146
转载 Python - Django - ORM 常用字段
AutoField:int 自增列,必须填入参数 primary_key=True如果没有写 AutoField,则会自动创建一个列名为 id 的列from django.db import modelsclass Person(models.Model): id = models.AutoField(primary_key=True) # 自增...
2019-08-01 18:38:00
92
转载 Python - Django - 命名 URL 和反向解析 URL
命名 URL:test.html:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>测试页面</title></head><body><p>...
2019-08-01 15:45:00
135
转载 Python - Django - 路由系统
URL 配置:urls.py 中的基本配置:from django.conf.urls import urlfrom app01 import viewsurlpatterns = [ url(正则表达式, views 视图函数[, 参数, 别名]),]在 Django 2 版本后将 url 改为 pathfrom django....
2019-07-31 17:21:00
95
转载 Python - Django - JsonResponse 对象
用 json 模块和 HttpResponse 返回生成的 jsonviews.py:from django.shortcuts import render, HttpResponseimport json# json 测试def json_test(request): data = {"name": "Jack", "age": 18} ...
2019-07-30 20:30:00
420
转载 Python - Django - request 对象
request.method:获取请求的方法,例如 GET、POST 等views.py:from django.shortcuts import render, HttpResponse# request 对象def test(request): print(request.method) return render(request, "...
2019-07-30 18:27:00
189
转载 Python - Django - FBV 和 CBV
FBV:Function Base View,基于函数的视图views.py:from django.shortcuts import render, HttpResponse# FBVdef upload(request): if request.method == "POST": filename = request.FIL...
2019-07-30 17:50:00
111
转载 Python - Django - 上传文件
upload.html:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>上传页面</title></head><body><form action=...
2019-07-30 17:32:00
78
转载 Python - Django - simple_tag 和 inclusion_tag
simple_tag:simple_tag 和自定义 filter 类似,但可以接收更多更灵活的参数在 app01/templatetags/ 目录下创建 mysimple_tag.pymysimple_tag.py:from django import templateregister = template.Library()@register....
2019-07-29 20:51:00
191
转载 Python - Django - 静态文件相关
静态文件的路径设置在 settings.py 中如果该路径发生更改的话,html 中相关路径也要进行修改CSS:<link href="/static/dashboard.css" rel="stylesheet">可以写成:{% load static %}<link href="{% static "dashboard.css...
2019-07-29 19:27:00
59
转载 Python - Django - 组件
网站中通常会有一个导航条,如下图这个导航条在很多页面都会存在可以把导航条做成一个组件,让要显示导航条的网页包含导航条组件 nav.html:<h1>假装这是一个导航条</h1>用 muban_test.html 来导入:<hr>{# 导入导航条组件 #}{% include 'nav.html' %}...
2019-07-29 18:05:00
93
转载 Python - Django - 母版和继承
可以把多个页面相同的部分提取出来,放在一个母板里,这些页面只需要继承这个母板就好了通常会在母板中定义页面专用的 CSS 块和 JS 块,方便子页面替换定义块:{% block 名字 %}{% endblock %}views.py 中添加函数:from django.shortcuts import render, redirect, HttpRe...
2019-07-29 17:21:00
134
转载 Python - Django - 模板语言之 Tags(标签)
标签使用 {% %}注释语句:{# #}for 循环:views.py:from django.shortcuts import render, redirect, HttpResponsefrom app01 import models# Filter 测试def filter_test(request): hobby = ["Read...
2019-07-26 21:29:00
150
转载 Python - Django - 模板语言之自定义过滤器
自定义过滤器的文件:在 app01 下新建一个 templatetags 的文件夹,然后创建 myfilter.py 文件这个 templatetags 名字是固定的,myfilter 是自己起的myfilter.py:from django import templateregister = template.Library()@register...
2019-07-26 20:50:00
166
转载 Python - Django - 模板语言之 Filters(过滤器)
通过管道符 "|" 来使用过滤器,{{ value|过滤器:参数 }}Django 的模板语言中提供了六十个左右的内置过滤器urls.py:from django.conf.urls import urlfrom django.contrib import adminfrom app01 import viewsurlpatterns = [ u...
2019-07-26 19:56:00
445
转载 Python - Django - 模板语言之变量
前言:在 Django 模板语言中变量用 {{ }},逻辑用 {% %}在 urls.py 中添加对应关系from django.conf.urls import urlfrom django.contrib import adminfrom app01 import viewsurlpatterns = [ url(r'^test/', vie...
2019-07-25 22:57:00
327
转载 Python - Django - 编辑作者
在作者列表页面的操作栏中加上编辑按钮<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>作者列表</title></head><body><h1>...
2019-07-24 22:39:00
186
转载 Python - Django - 删除作者
修改 author_list.html,添加删除按钮<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>作者列表</title></head><body>&l...
2019-07-24 20:40:00
179
转载 Python - Django - 添加作者
在 book_list.html 的页面下方加上 “添加作者” 的链接<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>作者列表</title></head><body&...
2019-07-24 20:00:00
338
转载 Python - Django - 显示作者列表
在 views.py 中添加展示作者列表的函数from django.shortcuts import render, redirect, HttpResponsefrom app01 import models# 展示出版社列表def publisher_list(request): pass# 添加新的出版社def add_pub...
2019-07-24 17:10:00
297
转载 Python - Django - 作者表多对多关联书籍表
models.py 代码:from django.db import models# Create your models here.# 出版社class Publisher(models.Model): id = models.AutoField(primary_key=True) # 自增的 id 主键 # 创建一个 varcha...
2019-07-24 15:11:00
230
转载 Python - Django - 使用 Bootstrap 样式修改书籍列表
展示书籍列表:首先修改原先的 book_list.html 的代码:<!DOCTYPE html><!-- saved from url=(0042)https://v3.bootcss.com/examples/dashboard/ --><html lang="zh-CN"><head> <met...
2019-07-23 22:04:00
268
转载 C++ - 第一个程序
代码:#include <iostream>using namespace std;int main(){ cout << "hello!" << endl; cout << "welcome to c++!" << endl; return 0;}运行结果:#in...
2019-07-12 13:54:00
147
转载 Python - Django - ORM 实例(二)
在 app01/models.py 中添加 Book 类对象表from django.db import models# Create your models here.# 出版社class Publisher(models.Model): id = models.AutoField(primary_key=True) # 自增的 ID 主键...
2019-04-25 22:58:00
96
转载 Python - Django - ORM 实例
准备工作:首先创建一个名为 Py_Django 的数据库新建项目,名为 mysite0创建完成后需要进行几项配置mysite0/settings.py 下首先是 html 文件相关其次是数据库配置最后注释掉 CSRF 的代码在 mysite0/__init__.py 中添加以下代码import pymysqlpymysql....
2019-04-23 20:33:00
82
转载 Python - Django - ORM 操作数据
查询数据(查询管理员):app01/models.py 中定义的类,也就是创建的表from django.db import models# 类必须继承 models.Modelclass Admin(models.Model): # 创建一个主键自增的字段 id = models.AutoField(primary_key=True) ...
2019-04-07 20:22:00
75
转载 Python - Django - 使用 Pycharm 连接 MySQL 数据库
在 Pycharm 的右上方找到 Database点击依次点击,选择 MySQL 数据库点击 Download 下载驱动文件下载完成后对数据库的相关信息进行填写填写完成后点击“Test Connection”,如果出现 Successful 就说明连接成功然后点击“应用”,再点击“确定”左边这个窗口是写 SQL 语句的地方例如查询 a...
2019-04-07 18:32:00
271
转载 Python - Django - ORM 操作表
ORM 的对应关系:类 ---> 数据库表对象 ---> 数据库行属性 ---> 字段操作数据库表 ---> 创建/删除/修改表操作数据库行 ---> 数据的增删改查首先需要自己手动创建一个数据库在 mysite 的 settings.py 中找...
2019-04-06 22:43:00
84
转载 Python - Django - App 的概念
App 方便我们在一个大的项目中,管理实现不同的业务功能创建 App:命令行:python manage.py startapp app名使用 Pycharm 创建:文件 -> 新建项目然后要在 mysite 下的 settings.py 中进行相关的配置两个写一个就好了一个 app 会带有以下这些文件apps.py ...
2019-04-06 20:23:00
267
转载 Python - Django - 登录页面
登录页 login.html:<!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8"> <meta http-equiv="x-ua-compatible" content="IE=edge"> <meta ...
2019-04-02 22:35:00
606
转载 WinRAR 代码执行漏洞复现
影响版本:WinRAR < 5.70 Beta 1Bandizip < = 6.2.0.0好压(2345压缩) < = 5.9.8.10907360压缩 < = 4.0.0.1170测试版本:WinRAR 5.61工具地址:https://github.com/droe/acefile010 Editor、WinAce...
2019-03-01 23:16:00
197
转载 Ubuntu 提权漏洞(CVE-2019-7304)复现
漏洞描述:Ubuntu 版本:Ubuntu 18.10Ubuntu 18.04 LTSUbuntu 16.04 LTSUbuntu 14.04 LTS2.28 < snapd < 2.37 会存在该漏洞Poc Github:https://github.com/initstring/dirty_sock#1注册并登陆,https:...
2019-02-28 21:42:00
1822
转载 Ubuntu 中安装 Docker
检查 Device Mapper 是否存在sch01ar@ubuntu:~$ ls -l /sys/class/misc/device-mapper安装 Ubuntu 维护的版本sch01ar@ubuntu:~$ sudo apt-get install docker.io安装完之后查看 docker 的版本sch01ar@ubuntu...
2019-01-03 18:36:00
79
转载 Ubuntu 升级内核版本
查看当前内核版本sch01ar@ubuntu:~$ uname -rUbuntu 内核地址:https://kernel.ubuntu.com/~kernel-ppa/mainline/打开这个文件夹下载这三个文件sch01ar@ubuntu:~$ wget https://kernel.ubuntu.com/~kernel-ppa/mai...
2019-01-03 17:01:00
174
转载 CVE-2018-8420 漏洞复现
影响的 Windows 版本:Microsoft Windows 10 Version 1607 for 32-bit SystemsMicrosoft Windows 10 Version 1607 for x64-based SystemsMicrosoft Windows 10 Version 1803 for 32-bit SystemsMicrosoft Windows 1...
2018-12-21 22:42:00
857
转载 Python - 第一个 Django 项目
Django 的安装:pip3 install django==1.11.11pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ django==1.11.11创建 Django 项目:一种方式是使用命令,django-admin startproject 项目名安装完 Django 之后...
2018-11-09 00:03:00
95
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅