DTCloud结合amis编辑器下篇~外联版

项目目录
image.png

最终需要展示的amis编辑器的html文件

参考编辑器源码链接

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="format-detection" content="telephone=no"/> <meta name="viewport" content="initial-scale=1,user-scalable=no,width=device-width,viewport-fit=cover"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>amis-editor Demo</title> <link rel="stylesheet" href="https://bce.bdstatic.com/iconfont/iconfont.css"/> <link rel="stylesheet" href="https://unpkg.com/[email protected]/animate.min.css"/> <link data-react-helmet="true" rel="shortcut icon" href="https://avatars.githubusercontent.com/u/78204817?s=200&v=4"/> <link href="https://aisuda.github.io/amis-editor-demo/demo/css/vendor.fcbe040c.css" rel="stylesheet"><link href="https://aisuda.github.io/amis-editor-demo/demo/css/index.ed44d890.css" rel="stylesheet"></head> <body> <div id="root"></div> <script defer src="https://aisuda.github.io/amis-editor-demo/demo/scripts/chunk/vendor.41754546.js"></script><script defer src="https://aisuda.github.io/amis-editor-demo/demo/scripts/chunk/index.36c0b146.js"></script></body> </html> 

控制器main.py

import os
from dtcloud import http
from jinja2 import Environment, FileSystemLoader
from dtcloud.addons.web.controllers.home import Home

# 是os找到模块的路径
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# 解析静态资源路径
templateLoader = FileSystemLoader(searchpath=BASE_DIR + "/static/dist")
# 加入到环境中
env = Environment(loader=templateLoader)


class Editor(Home):
  @http.route('/editor_zip', type='http', auth="none", csrf=False, method=["POST", 'get'],
              website=True, cors="*")
  def editor_zip_preview(self, **kwargs):
    """
    示例:http://127.0.0.1:9099/editor_zip
    端口根据自己项目 dtcloud.conf 中定义的 xmlrpc_port 值
    """
    values = dict()
    # 获取模板文件
    template = env.get_template('/index.html')
    # 渲染 
    html = template.render(object=values)
    return html

控制器__init__.py

from . import main

视图xml文件,不需要填写内容,但需要有

<?xml version="1.0" encoding="utf-8"?>
<dtcloud>
    <data></data>
</dtcloud>

根路径__init__.py

from . import controllers

manifest.py 按照默认的,不用引入文件

作者:白马不是马

猜你喜欢

转载自blog.csdn.net/ekcchina/article/details/130480296