前记:知识无处不在,要懂得珍惜,找到适合自己的方法高效地学习有价值的知识,不念过去,不畏将来。

Django对待静态资源,在非前后端分离时的常识

Django会对项目app下的static文件夹的静态资源进行收集,同名则按优先级指向,要自己加资源可以在settings.py的STATICFILES_DIRS进行额外指定,STATIC_URL=‘/static/',会对外监听例如:127.0.0.1:8000/static/*,STATIC_ROOT = os.path.join(BASE_DIR,'all_static')用于项目生产部署,在项目的开发过程中作用不大,平时都是前后端分离的,对生产环境的STATIC_ROOT没有感知,还不如好好学一下vue。

在云服务器部署项目时,Nginx正向代理

代理静态资源时,如果是build完的文件夹放服务器要注意位置,绝对路径或正确的相对路径,相对路径是基于nginx.conf进行相对的,include的配置文件别搞错了,还是绝对路径稳,然后要注意Windows和Centos7的文件资源路径为\和/的区别。

关于Django的Form校验json格式

在上传购物车之类的复杂数据时,可用json进行包装,Form对json进行校验,使用json_schema,之前都是根据检验目标自己写json_schema,后来发现可以在线生成的。例如:https://jsonschema.net/

class FormAddOrder(forms.Form):  # 新增订单校验json
json_data_str = forms.CharField(max_length=1024) def clean(self): # 重写clean,可以覆盖jaon_data_str,这里没覆盖
cleaned_data = self.cleaned_data
json_data = json.loads(cleaned_data["json_data_str"])
json_schema = {
"type": "object",
"required": ["type", "client", "warehouse", "send_way", "count_type", "real_price",
"need_price", "orders"],
"properties": {
"type": {"type": "string"},
"client": {"type": "integer"},
"warehouse": {"type": "integer"},
# "cabinets": {"type": "string"},
"send_way": {"type": "string"},
"count_type": {"type": "string"},
"real_price": {"type": "number"},
"need_price": {"type": "number"},
"orders": {
"type": "array",
"items": {
"type": "object",
"required": ["num", "need_price", "new_need_price", "batch", "goods"],
"properties": {
"num": {"type": "integer"},
"need_price": {"type": "number"},
"new_need_price": {"type": "number"},
"batch": {"type": "string"},
"goods": {"type": "integer"},
}
}
},
}
}
try:
validate(json_data, json_schema)
except Exception as e:
raise forms.ValidationError(e)
return cleaned_data

校验对象:

{
"type": "销售订单",
"client": 11,
"warehouse": 1,
"cabinets": "aa564879564",
"send_way": "快递",
"count_type": "现结付清",
"real_price": 3000,
"need_price": 3888,
"orders": [{
"num": 100,
"need_price": 110,
"new_need_price": 100,
"batch": "2019888",
"goods": 1
}, {
"num": 200,
"need_price": 220,
"new_need_price": 200,
"batch": "2019888",
"goods": 1
}]
}

最新文章

  1. Java连接程序数据源
  2. ACM/ICPC 之 一道不太简单的DP面试题(Geeksforgeeks)
  3. C/C++内存分配区
  4. C# 线程(二):关于线程的相关概念
  5. 在linux上使用"scp"命令拷贝一个目录到另一台服务器的时候报"not a regular file"错误的解决办法
  6. Cent OS 6 主机名设置
  7. CSS-div漂浮
  8. codevs1099字串变换(Bfs)
  9. mybatis的详解
  10. 《生活在Linux中》之:prefer function to alias in Bash
  11. DotNetZip 压缩下载
  12. C++编程练习(12)----“有向图的拓扑排序“
  13. rsyslog+mariadb+loganalyzer实现日志服务器搭建
  14. 广义后缀树(GST)算法的简介
  15. Java课程设计 购物车系统(个人博客)
  16. Android接口Parcelable的使用
  17. 使用msi自动安装系统
  18. docker的理解
  19. Axure 验证码、进度条、分页条(翻页)、搜索框、选项卡
  20. 【C/C++】程序如何来,编译全过程

热门文章

  1. [NOIP2015普及组]求和
  2. 自己动手写java锁
  3. (Review cs231n) Object Detection
  4. python小知识点随笔
  5. Windows7 安装TensorFlow,python3.6
  6. react 父子组件通信
  7. TeamCity 创建docker构建步骤
  8. ltp-ddt emmc_dd_rw
  9. 用户和用户组y哦不过y哦那个好
  10. Centos7.2(linux)minimal install之后需要的操作