python flask Jinja2模板 模板变量 如何赋值给 js 变量
python flask Jinja2模板 模板变量 如何赋值给 js 变量
python:
# 编辑分类 - 页面
@backhome_content.get('/category/edit/<int:id>')
@authorize("admin:content:category_save", log=True)
def category_edit(id):
category = curd.get_one_by_id(ContentCategory, id)
if category is None:
return fail_api(msg="获取分类详情失败")
data = curd.model_to_dicts(schema=ContentCategorySchema, data=[category])
return render_template('backhome/content/category_edit.html',id=id,category=data[0])Jinja2模板 js:
let id = '{{id|safe}}'
let category = JSON.parse('{{category|tojson}}')
console.log('id',id,'category',category);