I am trying to deploy a Django project to Apache 2.4 using mod-wsgi, on Windows 11 (and later Windows Server). The project works when I do python manage.py runserver
, but it fails when I try to run httpd from Apache24/bin, reporting that:
TemplateDoesNotExist at /
My project is in the folder: C:/django/f2db_py
The project is called: f2db
The folder C:/django is set so all users have “full control” permission
My httpd.conf file has this in it towards the top:
LoadFile "C:/Python311/python311.dll"
LoadModule wsgi_module "C:/Python311/Lib/site-packages/mod_wsgi/server/mod_wsgi.cp311-win_amd64.pyd"
WSGIPythonHome "C:/Python311"
WSGIScriptAlias / C:/django/f2db_py/f2db/wsgi.py
WSGIPythonPath C:/django/f2db_py
<Directory C:/django/f2db_py/f2db>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
And at the bottom:
Alias /static C:/django/f2db_py/static
<Directory /static>
AllowOverride None
Options All
Require all granted
</Directory>
Here is the Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: C:\Users\andyj\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\django\f2db_py\computers\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Python311\Lib\site-packages\django\contrib\admin\templates\home.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Python311\Lib\site-packages\django\contrib\auth\templates\home.html (Source does not exist)
Where it should be looking is: C:\django\f2db_py\templates
The first line looks to be derived from where I run httpd from, C:\Users\andyj, and indeed if I run httpd from C:\django\f2db_py it finds the template. I want to run this as a service, so running from that folder is not a long term solution.
I am guess there is a setting for the project home directory, and it is defaulting to the current one. But I cannot work out what that is.