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

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. FB面经 Prepare: Largest Island

    Find largest island in a board package fb; public class LargestIsland { public int findLargestIsland ...

  2. js左右大小变化

    点左边左边变大.点右边右边大左边小 <style type="text/css"> *{ margin:0px auto; padding:0px; } #wai{ w ...

  3. iOS 如何在自定义类中支持 "[]" 运算符

    在相应类中实现如下协议即可. 1.字典类 - (id)objectForKeyedSubscript:(NSObject <NSCopying> *)key; - (void)setObj ...

  4. 集合 set

    集合 集合属于可变数据类型,但它的内容必须是不可变数据类型. 特点:无序   ,  不重复 有两种创建方式: set({1,2,3})和 {1,2,3} set1 = set({1,2,3,4}) s ...

  5. Scala字节数组转换为数字

    1. 2个字节数组转换为整数 def bytes2uint8(_bytes: Array[Byte], _offset: Int): Int = { val b0 = _bytes(_offset) ...

  6. laravel composer

    composer config -g repo.packagist composer https://packagist.phpcomposer.com 改安装包的全局镜像网址

  7. python 类的属性__slots__ (了解一点点)

    当一个类需要创建大量实例时,可以通过__slots__声明实例所需要的属性, 优点: 1)更快的属性访问速度 2)减少内存消耗 3)限定一个类创建的实例只能有固定的实例属性(实例变量),不允许对象添加 ...

  8. Lists.newArrayListWithExpectedSize( int estimatedSize)

    Lists.newArrayListWithExpectedSize( int estimatedSize)  构造一个期望长度为estimatedSize的ArrayList实例. 源码: publ ...

  9. STD函数的内部计算公式

    各股票软件的标准差函数STD是不同的,而布林线的上下轨是以STD为基础计算出来的,所以使用布林线应小心.以2008/3/28的上证综指为例,利用如下代码:"收盘价3日STD:STD(CLOS ...

  10. 自动获取客户端的ip地址

    document.writeln('<script src=\"http://pv.sohu.com/cityjson?ie=utf-8\"></script&g ...