PerryDaPlatypus PerryDaPlatypus - 3 months ago 12
Python Question

Do the Templates in django need to move to public while using Passenger

Very familiar with python and Flask, but just getting started with Django.

ENVIRONMENT

Dreamhost, Django 1.9 (i think), python 2.7.3, Passenger

PROBLEM STMT

I have my app working and can generate an index page using HttpResponse straight from views.py. However, when I try to incorporate templates, I am getting "TemplateDoesNotExist at /"

Because I'm new, I'm not sure where to start troubleshooting. Is this a passenger issue or Django?

DETAILS

I've modified my [DIRS] in settings.py to reference the templates directory.

'DIRS': ['CTracker/templates'],


I then created the templates directory under CTracker and the 'clientadmin' (the name of my app) directory and finally the index.html file.

-CTracker
|
|-CTracker
| |
| -templates
| |
| -clientadmin
| |
| -index.html
|-manage.py


My function in views.py uses the following return.

return render(request, 'clientadmin/index.html', {
'clients': client,
})


Troubleshooting Done


  • Double checked the files exist and the path to the file appears
    correct in both the filesystem and the settings.py file.

  • I tried running 'manage.py collectstatics' but 0 files were moved.



Thank you in advance. Any help is appreciated.

Answer

The items in the DIRS list should be the full path, for example:

'DIRS': ['/path/to/CTracker/CTracker/templates'],

The Django settings file should have a BASE_DIR defined. You can use this with os.path.join to avoid hardcoding the full path.

'DIRS': [os.path.join(BASE_DIR, 'CTracker', 'templates')]