1

I used pyinstaller to create an executable, but I am getting these errors when I run the executable:

> 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

When I run this script locallly, it all works fine.

Here is the script:

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

To build the executable I used:

pyinstaller --onefile testforms.py

I also tried:

return render_template('template.html' ) 
jwpfox
  • 5,124
  • 11
  • 45
  • 42
James Cook
  • 11
  • 1
  • 2
  • I also tried: return render_template('template.html' ) – James Cook Nov 10 '16 at 23:14
  • Possible duplicate of [Flask application built using pyinstaller not rendering index.html](https://stackoverflow.com/questions/32149892/flask-application-built-using-pyinstaller-not-rendering-index-html) – Chai Ang Jun 26 '18 at 08:25

1 Answers1

0

i encountered the same issue. But i didn't make one file. I just copy static and template folder and paste in "dist/main" folder. Its works for me

Sathish Kumar
  • 341
  • 1
  • 3
  • 8
  • Doesn't it defeat the purpose of bundling the app into a package (using PyInstaller) and distributing it as an executable? – Palak Jain Jan 21 '22 at 17:48