0

I converted a Django project to exe file and launch it. But in browser it shows an error saying the page not found.

C:.
|   db.sqlite3
|   list.txt
|   manage.py
|   
+---account
|   |   admin.py
|   |   apps.py
|   |   models.py
|   |   tests.py
|   |   urls.py
|   |   views.py
|   |   __init__.py
|   |   
|   +---migrations
|   |   |   __init__.py
|   |   |   
|   |   \---__pycache__
|   |           __init__.cpython-310.pyc
|   |           
|   +---templates
|   |   \---account
|   |           customers.html
|   |           dashboard.html
|   |           main.html
|   |           navbar.html
|   |           products.html
|   |           status.html
|   |           
|   \---__pycache__
|           admin.cpython-310.pyc
|           apps.cpython-310.pyc
|           models.cpython-310.pyc
|           urls.cpython-310.pyc
|           views.cpython-310.pyc
|           __init__.cpython-310.pyc
|           
+---crm
|   |   asgi.py
|   |   settings.py
|   |   urls.py
|   |   wsgi.py
|   |   __init__.py
|   |   
|   \---__pycache__
|           settings.cpython-310.pyc
|           urls.cpython-310.pyc
|           wsgi.cpython-310.pyc
|           __init__.cpython-310.pyc
|           
\---static
    +---css
    |       main.css
    |       
    +---images
    \---js

The command to package the project: pyinstaller --name=crm manage.py and the command to launch the exe file: crm.exe runserver localhost:8000 --noreload. The exe file is in the dist folder.

When I try to open the browser with 127.0.0.1/8000 the error shows :

TemplateDoesNotExist at /
account/dashboard.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 4.1
Exception Type: TemplateDoesNotExist
Exception Value:    
account/dashboard.html
Exception Location: django\template\loader.py, line 19, in get_template
Raised during:  account.views.home

It seems that subfolders are not embedded in the exe. Could someone give me a hint how to solve the problem?

BabyHai
  • 89
  • 1
  • 9

1 Answers1

0

Following this question, I added overcame this problem by adding the templates directly to the installer using:

datas=[('xxx/templates','xxx/templates')]

in my .spec file, where "xxx" is whatever the app name is.

It seems like pyinstaller should automatically pick these up and I'm just working around the problem, masking the underlying cause, so if anyone has a better answer, I'd be happy to hear it too.