无法返回烧瓶中的html页面

时间:2020-07-02 18:53:30

标签: html flask

我有一个flask项目,其中有一个端点返回 return ''' <h1> Inserted succesfully . Click this link to <a href = "moviehome.html"> go to home page </a> </h1> ''',我想在该端点上单击href文本"go to home page"返回到我的主页。但是,当我单击它时, 404 URL not found on the server 错误。我也尝试<a href = "{{url_for('home')}}">插入端点的名称,但结果相同

我的家庭终点:

#home page
@app.route('/')
def home():
    
    return render_template('moviehome.html')

非常感谢您帮助解决此问题。预先谢谢你。

1 个答案:

答案 0 :(得分:1)

return '''
<h1> Inserted succesfully . Click this link to
  <a href = "{{ url_for('home') }}"> go to home page </a>
</h1>
'''

您只返回带有docstring字母的普通字符串jijna2表达式不会被解析,而是解释为字符串。

解决方案是使用字符串连接之类的

return '''
<h1> Inserted succesfully . Click this link to 
  <a href = " ''' + url_for('home') + ''' "> go to home page </a>
</h1>
'''