2017-05-26 103 views
1

我正在嘗試採用模塊化方法來設計我的Flask應用程序。無法用BluePrints Flask找到模板

所以每個模塊都是多個路由。見下面

enter image description here

Templates文件夾

enter image description here

我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) 

believe_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) 

內容的初始化的.py

from home_routes import home_blueprints 
from believe_routes import believe_blueprints 

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

只有home_routes工作。 believe_routes中的URL不起作用。我從create_app 404

INFO  2017-05-26 18:01:44,325 module.py:813] default: "GET /home/Believe/Truth_About_Christ HTTP/1.1" 404 233 

我打電話configure_blueprints(應用程序),然後從main.py.稱爲

請任何想法。

+0

你能分享你的模板文件夾的截圖嗎? –

+0

模板文件夾的屏幕截圖已添加。 –

+0

謝謝。其實準確的設置工作在我的最後。我無法弄清楚是什麼引起了這個錯誤。 –

回答

0

404不爲模板的原因,也許你可以試試這個代碼來查看藍圖是否臨時用戶到燒瓶實例,你可以把你的背部輸出更多詳細信息...

#!/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) 

我希望這可以幫助你..

+0

我在url_map中看到以下內容 –

+0

Map([home_routes.confirmation>,home_routes.contact>,home_routes.links>,home_routes.map>,admin.admin_landing>,home_routes.main>,'(HEAD,OPTIONS,GET) - >靜態>,'(HEAD,OPTIONS,GET) - > home_routes.static>,'(HEAD,OPTIONS,GET) - > admin.static>]) –

+0

'believe_blueprints'沒有註冊到Flask,也許有一些東西代碼錯誤,你可以粘貼所有調用'configure_blueprints'的代碼嗎? @VinayJoseph – Liqiang