使用 django 模板的 extend 方法,子模板中只需要配置 AmisJson 对象即可。标签:body,name,title,方法,Django,width,let,type,Amis From: https://www.cnblogs.com/shentian123/p/17100101.html
templates中的代码如下:
<!DOCTYPE html>
{% load static %}
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>{% block title %} 我的站点 {% endblock title %}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link rel="stylesheet" href="{% static 'sdk/sdk.css' %}" />
<link rel="stylesheet" href="{% static 'sdk/helper.css' %}" />
<link rel="stylesheet" href="{% static 'sdk/iconfont.css' %}" />
<style>
{% block style %}
html,
body,
.app-wrapper {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
{% endblock style %}
</style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="{% static 'sdk/sdk.js' %}"></script>
<script type="text/javascript">
(function () {
let amis = amisRequire('amis/embed');
// 通过替换下面这个配置来生成不同页面
let amisJSON = {% block amisjson %}
{
type: 'page',
title: '表单页面',
body: {
type: 'form',
mode: 'horizontal',
api: '/saveForm',
body: [
{
label: '账号',
type: 'input-text',
name: 'name'
},
{
label: '密码',
type: 'input-email',
name: 'email'
}
]
}
}
{% endblock amisjson %};
let amisScoped = amis.embed('#root', amisJSON);
})();
</script>
</body>
</html>