Python 找不到带有蓝图的模板

Python 找不到带有蓝图的模板,python,flask,Python,Flask,我正在尝试采用模块化的方法来设计我的Flask应用程序 因此,每个模块都有多条路由。见下文 模板文件夹 my home_routes.py的内容 from flask import Blueprint, request, session, abort from flask import render_template def home_blueprints(app): home_routes = Blueprint("home_routes", __name__, templat

我正在尝试采用模块化的方法来设计我的Flask应用程序

因此,每个模块都有多条路由。见下文

模板文件夹

my home_routes.py的内容

from flask import Blueprint, request, session, abort
from flask import render_template


def home_blueprints(app):
    home_routes = Blueprint("home_routes", __name__, template_folder='../../templates', static_folder='../../static')

    @home_routes.route('/home/Links')
    def links():
        return render_template('links.html')

    @home_routes.route('/home/Confirmation')
    def confirmation():
        return render_template('Confirmation.html')

    @home_routes.route('/')
    def main():
        return render_template('main.html')

    @home_routes.route('/home/Contactus', methods=['GET', 'POST'])
    def contact():
        if request.method == "POST":
            token = session.pop('_csrf_token', None)
            if not token or token != request.form.get('_csrf_token'):
                abort(403)
        return render_template('GoogleForm.html')


    app.register_blueprint(home_routes)
信_.py的内容

from flask import Blueprint
from flask import render_template


def believe_blueprints(app):
    believe_routes = Blueprint("believe_routes", __name__, template_folder='../../templates', static_folder='../../static')

    @believe_routes.route('/home/Believe/Truth_About_God')
    def truth_about_God():
        return render_template('The_Truth_Concerning_God.html')

    @believe_routes.route('/home/Believe/Truth_We_Believe')
    def the_truth_we_beleive():
        return render_template('The_Truth_We_Believe.html')

    @believe_routes.route('/home/Believe/Truth_About_Christ')
    def truth_about_christ():
        return render_template('The_Truth_About_Christ.html')

    @believe_routes.route('/home/Believe/Truth_About_Church')
    def truth_about_church():
        return render_template('The_Truth_About_Church.html')

    @believe_routes.route('/home/Believe/Truth_About_Salvation')
    def truth_about_salvation():
        return render_template('The_Truth_About_Salvation.html')

    @believe_routes.route('/Believe')
    def truth_we_believe():
        return render_template('Truth_We_Believe.html')

    app.register_blueprint(believe_routes)
init.py的内容

from home_routes import home_blueprints
from believe_routes import believe_blueprints

def configure_blueprints(app):
    home_blueprints(app)
    believe_blueprints(app)
只有回家的路线有效。信任路由中的URL不起作用。我有一个404

INFO     2017-05-26 18:01:44,325 module.py:813] default: "GET /home/Believe/Truth_About_Christ HTTP/1.1" 404 233
我正在从create_应用程序调用configure_blueprints(应用程序),然后从main.py调用create_应用程序


有什么想法吗

404不是因为模板的原因,也许您可以尝试使用此代码查看blueprint是否已注册到flask实例,并且您可以将输出放回flask以获取更多详细信息

#!/usr/bin/env python
# encoding: utf-8
from flask import Flask

from home_routes import home_blueprints
from believe_routes import believe_blueprints


app = Flask('demo')


def configure_blueprints(app):
    home_blueprints(app)
    believe_blueprints(app)

configure_blueprints(app)
print(app.url_map)

我希望这会对您有所帮助。

404不是出于模板原因,也许您可以尝试使用此代码查看blueprint是否已注册到flask实例,并且您可以将输出放回以获取更多详细信息

#!/usr/bin/env python
# encoding: utf-8
from flask import Flask

from home_routes import home_blueprints
from believe_routes import believe_blueprints


app = Flask('demo')


def configure_blueprints(app):
    home_blueprints(app)
    believe_blueprints(app)

configure_blueprints(app)
print(app.url_map)

我希望这会对您有所帮助。

您能分享模板文件夹的截图吗?已添加模板文件夹的截图。谢谢。事实上,我这边的设置是正确的。我不知道是什么原因导致了你的这个错误。你能分享你的模板文件夹的截图吗?模板文件夹的截图已经添加。谢谢。事实上,我这边的设置是正确的。我无法找出导致您端出现此错误的原因。我在url\u地图中看到以下内容([home\u routes.confirmation>、home\u routes.contact>、home\u routes.links>、home\u routes.map>、admin.admin\u landing>、home\u routes.main>、'(HEAD,OPTIONS,GET)->home\u routes.static>、'(HEAD,OPTIONS,GET)->home\u routes.static>、'(HEAD,OPTIONS,GET)->admin.static>)
相信\u blueprints
没有注册到Flask,可能代码中有错误,您能粘贴调用
配置\u blueprints
的所有代码吗@VinayJoseph在url\u地图中看到了以下内容([home\u routes.confirmation>,home\u routes.contact>,home\u routes.links>,home\u routes.map>,admin.admin\u landing>,home\u routes.main>,”(HEAD,OPTIONS,GET)->home\u routes.static>,”(HEAD,OPTIONS,GET)->admin.static>)
相信\u blueprints
没有注册到Flask,可能代码中有错误,您能粘贴调用
配置\u blueprints
的所有代码吗@维奈约瑟夫