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

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
}]
}

杂记:Django和static,Nginx配置路径,json_schema的更多相关文章

  1. nginx配置路径问题

    编译了一个程序放在服务器上,通过nginx配置转发访问.例如在配置下图的地址 d:\wayne\nginxWeb\www: 发现无法正常运行,查看error.log发现是有问题的,当创建文件时,ngi ...

  2. [Django笔记] uwsgi + nginx 配置

    django 和 nginx 通过 uwsgi 来处理请求,类似于 nginx + php-fpm + php 安装nginx 略 安装配置uwsgi pip install uwsgi 回想php- ...

  3. Django 下static的配置

    1.添加一个BASE_DIR在setting.py中,如果已存在可不用添加,需引入 import os BASE_DIR = os.path.dirname(os.path.dirname(os.pa ...

  4. mac上php+nginx配置

    brew的安装: ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”php安装和配置bre ...

  5. yum 安装nginx(配置开机启动)

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...

  6. 简易配置Django的Static文件

    http://blog.csdn.net/hireboy/article/details/8806098 Django 1.3以后,采用static方式处理静态文件,比如网站的css js image ...

  7. django wsgi nginx 配置

    """ WSGI config for HelloWorld project. It exposes the WSGI callable as a module-leve ...

  8. Django部署uwsgi 与 nginx配置

    1.nginx文件的配置 路径:/etc/nginx/conf.d/ example.conf 启动:service nginx [start]/[restart]/[stop] upstream d ...

  9. django开发过程中静态文件路径配置

    在demo项目的settings.py文件中找到 STATICFILES_DIRS STATICFILES_DIRS = ( 'static', #这个名字是项目根目录下的文件夹名称,注意后面有逗号 ...

随机推荐

  1. javascript中 for-in和 for-of的区别

    其中for-of是ES6新增的迭代语法 在MDN上的解释: for...in语句以任意顺序遍历一个对象的可枚举属性.对于每个不同的属性,语句都会被执行.for...of语句在可迭代对象(包括 Arra ...

  2. VS2008生成解决方案卡顿、龟速

    1.工具-选项-项目和解决方案-MS BUILD 项目生成输出详细信息中选择“诊断” 2.进入.NET环境的安装位置:C:\WINDOWS\Microsoft.NET\Framework\v3.5 , ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    C 模拟 题意:给的是一个矩形,然后√2 的速度走,如果走到边上就正常反射,走到角上,暂停反射,我们知道要不循环要不暂停,记录走到的点最短时间 /*************************** ...

  4. Java输出流FileOutputStream使用详解

    Java输出流FileOutputStream使用详解 http://baijiahao.baidu.com/s?id=1600984799323133994&wfr=spider&f ...

  5. selenium 定位密码软键盘

    from selenium import webdriver import time driver = webdriver.Chrome() driver.maximize_window() driv ...

  6. Matlab学以致用--模拟os任务装载情况

    2012-06-08 21:26:42 用matlab来建模,仿真不同时刻os task在队列中的装载情况.输入参数如下 作为初学者,M文件写的有点长.能实现功能就算学以致用了. clear;clc ...

  7. Android文件各种存储路径的比较

    1.File cacheDir = context.getCacheDir(); 应用内部存储空间(数据文件私有)文件存储到这个路径下,不需要申请权限,当应用被卸载的时候,目录下的文件会被删除. 需要 ...

  8. 解决 Cannot uninstall 'pyparsing' 问题

    参考 pyparsing 无法卸载导致安装 matplotlib 出错 解决 Cannot uninstall 'pyparsing' 问题 在安装 pydot 时遇到依赖 pyparsing 无法更 ...

  9. Ubuntu 14.04 安装 sysrepo v0.7.5

    参考: Tentative gNMI support with sysrepo protobuf-c/protobuf-c Ubuntu 14.04 安装 sysrepo v0.7.5 安装依赖: s ...

  10. Ubuntu 下生成 python 环境安装文件 requirements.txt

    参考: 查找python项目依赖并生成requirements.txt Ubuntu 下生成 python 环境安装文件 requirements.txt 首先通过 pip 安装pyreqs模块: p ...