首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Flask render_template返回的是字符串,而不是HTML文档

Flask render_template返回的是字符串,而不是HTML文档
EN

Stack Overflow用户
提问于 2019-03-04 06:37:45
回答 2查看 3.2K关注 0票数 0

我有这个函数:

代码语言:javascript
复制
def run():
  if request.method == 'POST':
    print(request.form['id_num'])
    # fix later                                                                                                                  
  else:
    return render_template("apprun.html")

现在,它总是指向else语句,但是render_template函数不能正常工作。我得到的代码不是一个完全格式化的HTML页面,而是一个字符串。具体地说,我的网页显示的是html,而不是读取html并正确显示:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<title>Rips Lab</title>
</head>                                 
<body>
<style type="text/css">
            html {
                background-color: #E4E0EE;
                }
           body {
                font-family: "Helvetica","Arial";
                font-size: 20px;
                color: #000000;
                }
</style>


<form>Enter participant ID number: <input type="number" name="id_num" pattern="^[0-9]*$" required></form>
<br><br>

<p name="data"></p>


</body>
</html>

文件夹层次结构是正确的;我将一个名为"templates“的文件夹存储在与我正在运行的python文件相同的位置。

你知道为什么它的格式不正确吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54974483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档