红叶゜ 2023-09-28 17:52 采纳率: 50%
浏览 3
已结题

(标签-python|关键词-File)

有没有人帮忙看看,蟹蟹
代码:
python:

def helloworld():
    platformList = [platform.value for platform in ModuleX]
    return render_template('test.html', platformList=platformList)

html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
    <div id="app">
        <el-container>
            <el-header>
                <h1>测试计划配置页</h1>
            </el-header>
            <el-main>
                <el-form ref="form" :model="form" label-width="80px" :inline="true" class="demo-form-inline">
                    <el-form-item label="平台">
                        <el-select v-model="form.platform" placeholder="请选择平台">
                            {% for platform in platformList %}
                                <el-option label={{ platform }} value={{ platform }}></el-option>
                            {% endfor %}
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary">查询</el-button>
                    </el-form-item>
                </el-form>
                <el-tabs :v-model="activeName">
                    <el-tab-pane
                        v-for="(file,index) in fileList"
                        :key="index"
                        :label="file.fileName"
                        :name="file.fileName"
                    >
                        {{ file.content }}
                    </el-tab-pane>
                </el-tabs>
            </el-main>
        </el-container>
    </div>
</body>
    <!-- import Vue before Element -->
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        new Vue({
        el: '#app',
        data: function() {
            return { 
                form: {
                    platform:''
                },
                fileList:[
                    {
                        fileName:'xml',
                        content:'xxx'
                    },{
                        fileName:'json',
                        content:'jjj'
                    }
                ],
                activeName:'json'
            }
        },
        methods: {
            async getPlatformConfig() {
                if (''==this.form.platform){
                    await this.$message.error('请选择需要查询的平台!');
                    return
                }
            }
        }
        })
    </script>
</html>

报错:

  File "./GSConfigServer.py", line 1451, in helloworld
    return render_template('test.html', platformList=platformList)
    return _render(app, template, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python\python311\Lib\site-packages\flask\templating.py", line 132, in _render
    rv = template.render(context)
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python\python311\Lib\site-packages\jinja2\environment.py", line 1301, in render
    self.environment.handle_exception()
  File "D:\python\python311\Lib\site-packages\jinja2\environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "D:\Project\dlspeed_all\server\GSConfigServer\webapp\test.html", line 34, in top-level template code
    {{file.content}}
  File "D:\python\python311\Lib\site-packages\jinja2\environment.py", line 485, in getattr
    return getattr(obj, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'file' is undefined

现象:

img

  • 写回答

3条回答 默认 最新

  • 红叶゜ 2023-10-08 09:43
    关注

    img

    img


    将括号转义即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月16日
  • 已采纳回答 10月8日
  • 专家已采纳回答 10月6日
  • 创建了问题 9月28日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号