我有一个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')
非常感谢您帮助解决此问题。预先谢谢你。
答案 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>
'''