js如何获取python后台配置数据

在python中我们的后台配置的数据是无法传到js中,js也无法进行获取,但是后台配置是可以通过jinja2模板引擎传到前端的,然后在js中获取前台的值,我们就可以以这种方式来进行获取值

#这个是后台config内的配置
UPLOAD = {
    'ext':['jpg','gif','bmp','jpeg','png'],
    'prefix_path':'/static/upload/',
    'prefix_url':'/static/upload/'
}
APP = {
    'domain':'http://127.0.0.1:9090'
}
<div class="hidden hidden_layout_wrap">
{# 获取config中的配置 #}
    <input name="domain" value="{{ config.APP.domain }}">
    <input name="prefix_url" value="{{ config.UPLOAD.prefix_url }}">
</div>
buildPicUrl:function (img_key) {
//拿到前台的值
    var domain = $(".hidden_layout_wrap input[name=domain]").val();
    var prefix_url = $(".hidden_layout_wrap input[name=prefix_url]").val();
    return domain + prefix_url + img_key;
}
posted on 2022-04-08 10:38  一纸荒年003  阅读(206)  评论(0)    收藏  举报