【发布时间】:2020-02-28 03:12:34
【问题描述】:
这是我如何创建一个简单的蓝图
from flask import Blueprint, render_template
my_bp_page = Blueprint('my_bp_page', __name__, template_folder='templates')
@my_bp_page.errorhandler(404)
def page_not_found(e):
return render_template('404.html', pageName='my_bp_page.home')
@my_bp_page.route('/home', methods=['GET'], strict_slashes=False)
def home():
return render_template('home.html')
这是我的404.html
{% block title %}Page Not Found{% endblock %}
{% block body %}
<h1>Page Not Found</h1>
<p>What you were looking for is just not there.
<p>
{% if pageName is defined %}
<a href="{{ url_for(pageName) }}">Go Back</a>
{% else %}
<a href="{{ url_for('home') }}">Go Back</a>
{% endif %}
{% endblock %}
在测试这个时,我尝试了 URL localhost:5000/home/junk 并且我看到了
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
这不是我应该看到的。我应该看到我的自定义404.html
我做错了什么?
【问题讨论】: