【问题标题】:pyinstaller Template not found找不到 pyinstaller 模板
【发布时间】:2016-11-10 22:28:30
【问题描述】:

我使用 pyinstaller 创建了可执行文件,但在运行可执行文件时出现以下错误:

> Traceback (most recent call last):
>       File "flask/app.py", line 1988, in wsgi_app
>       File "flask/app.py", line 1641, in full_dispatch_request
>       File "flask/app.py", line 1544, in handle_user_exception
>       File "flask/app.py", line 1639, in full_dispatch_request
>       File "flask/app.py", line 1625, in dispatch_request
>       File "testforms.py", line 13, in my_form
>       File "flask/templating.py", line 133, in render_template
>       File "jinja2/environment.py", line 851, in get_or_select_template
>       File "jinja2/environment.py", line 812, in get_template
>       File "jinja2/environment.py", line 774, in _load_template
>       File "flask/templating.py", line 57, in get_source
>       File "flask/templating.py", line 85, in _get_source_fast
>       TemplateNotFound: template.html

当我在本地运行此脚本时,一切正常。

这是脚本:

from flask import Flask                               
from flask import request                             
from flask import render_template                     
app = Flask(__name__, template_folder='templates')    

@app.route('/')                                       
def my_form():                                        
    return render_template('/template.html' )         

    @app.route('/', methods=['POST'])                     
 def my_form_post():                                   

    text = request.form['text']                       
    processed_text = text.upper()                     
    print processed_text                              
    return processed_text                             

if __name__ == '__main__':                            
    app.run()                         

构建我使用的可执行文件:

pyinstaller --onefile testforms.py

我也试过了:

return render_template('template.html' ) 

【问题讨论】:

标签: python pyinstaller


【解决方案1】:

我遇到了同样的问题。但我没有制作一个文件。我只是复制静态和模板文件夹并粘贴到“dist/main”文件夹中。它对我有用

【讨论】:

  • 这不是违背了将应用程序捆绑到一个包中(使用 PyInstaller)并将其作为可执行文件分发的目的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 2017-02-02
  • 2013-07-13
  • 2014-10-31
  • 1970-01-01
相关资源
最近更新 更多