首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Flask Blueprints查找我的模板?

如何使用Flask Blueprints查找我的模板?
EN

Stack Overflow用户
提问于 2015-03-25 02:12:16
回答 1查看 334关注 0票数 0

我已经搜索了所有我能找到的包括这个,flask blueprint template folder

代码语言:javascript
复制
/root
 __init__.py
 run.py
    /hrms
      __init__.py
      views.py
      models.py
    /static
    /templates
        __init__.py
        layout.html
        /hr
            __init__.py
            hr_template_test.html

我也尝试过:

代码语言:javascript
复制
/hrms
  __init__.py
  views.py
  models.py
  /templates
      __init__.py
      hr_template_test.html

无论我把hr_template_test.html文件放在哪里,Flask都找不到它。下面是我在__init__.py中拥有的内容

代码语言:javascript
复制
from flask import Blueprint, render_template

hrms_blue = Blueprint('hrms', __name__, template_folder='templates')

@hrms_blue.route('/')
def index():
    return render_template('hrms_data_view.html')

run.py

代码语言:javascript
复制
from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension
from application.views.hrms import hrms_blue

app = Flask(__name__)
app.register_blueprint(hrms_blue, url_prefix='/<hrms_id>')

我试过了:

代码语言:javascript
复制
return render_template('hr/hrms_data_view.html')
return render_template('application/templates/hr/hrms_data_view.html')
return render_template('templates/hr/hrms_data_view.html')
return render_template('hrms_data_view.html')

http://127.0.0.1/hrms

Jinja2抱怨说它找不到html文件。

我从模板和hr中取出了__init__.py。不我明白了TypeError: index() takes no arguments (1 given)

EN

回答 1

Stack Overflow用户

发布于 2015-03-25 03:29:02

您可能遇到了循环导入的问题。您应该尝试执行以下操作:

代码语言:javascript
复制
def register(app):
    from __init__ import hrms_blue
    app.register_blueprint(hrms_blue)

register(app)

而不是做:

代码语言:javascript
复制
app.register_blueprint(hrms_blue, url_prefix='/<hrms_id>')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29239935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档