我目前正在从事具有以下结构的项目:
ROOT
-js
-dist
-index.html
-bunch of other files that index.html uses
-src
-main.py
-doc_apps
-app1
-index.html
-other resources that index.html needs
-app2
-index.html
-other resources that index.html needs
现在我的烧瓶配置为:
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
COMPONENT_FOLDER = os.path.abspath(os.path.join(ROOT_DIR, '../'))
DIST_FOLDER = os.path.join(COMPONENT_FOLDER, 'js\\dist')
DOCUMENTATION_FOLDER = os.path.join(COMPONENT_FOLDER, 'documentation_data')
app = Flask(__name__, static_folder=DIST_FOLDER, template_folder=DIST_FOLDER, static_url_path='')
my_loader = jinja2.ChoiceLoader([
app.jinja_loader,
jinja2.FileSystemLoader(DOCUMENTATION_FOLDER),
])
app.jinja_loader = my_loader
@app.route('/')
def index():
"""
This the main entry to the application
Returns
-------
out
renders the 'index.html' file
"""
return render_template('index.html')
@app.route('/get_index_html', methods=['GET'])
def get_index_html():
index_html_path = request.args.get('path')
full_root = os.path.join(index_html_path).replace('\\','/')
return render_template(full_root)
启动我的应用程序并转到主页时,我无法呈现index.html(js / dist文件夹中的那个),并且一切正常。
当我尝试渲染内部index.html之一时,问题就开始了。
我能够自行呈现index.html,但出现以下错误
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/css/theme.css HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/pygments.css HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/js/modernizr.min.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/jquery.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/underscore.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/doctools.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/js/theme.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/jquery.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:43] "GET /_static/underscore.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:44] "GET /_static/doctools.js HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2018 18:08:44] "GET /_static/js/theme.js HTTP/1.1" 404 -
我可以说问题是它找不到正确生成此index.html所需的静态文件。
我如何才能知道对于这个特定的index.html使用some_static_folder? 我想知道是否有 render(html,static_folder = ...)
我想提到App1 / index.html中的每一个 有其自己的链接,并且那些链接依赖于App1的内部结构,因此如何配置当我发送App1 / index.html时,它将对从该App1 / index.html调用的所有内容使用一些static_folder
更多信息,也可以在服务器已经运行之后添加App1 / 2。
非常感谢您的帮助