python - correct template location for django generics? -


according django docs, template loader

load templates django apps on filesystem. each app in installed_apps, loader looks templates subdirectory.

going on:

...then get_template('foo.html') foo.html in these directories, in order:

/path/to/myproject/polls/templates/ /path/to/myproject/music/templates/ 

so... inside "website" project, have "www" app. directory structure /path/to/project/website/www/

i created "templates" directory inside "www", , put there "page_list.html" (/path/to/project/website/www/page_list.html)

the app listed inside "installed_apps", when try in urls.py:

url('^$', listview.as_view(model=page,)) 

i "templatedoesnotexist", , error says django.template.loaders.app_directories.loader looking "/path/to/project/website/templates/www/page_list.html" or /path/to/project/website/www/templates/www/page_list.html

if put template inside website/www/templates/www, works... wonder why works way. seems absurd have templates folder inside app folder, , have yet 1 named application inside templates directory....

and documentation says should looking inside of project/app/templates... have

template_dirs = [os.path.join(base_dir, 'templates')] 

although docs app_directories.loader don't need (and tried removing option).

what's going on? there i'm doing wrong? generic views, or there else afoot?

your problem automatic template naming of django's generic class based views. if use django.views.generic.listview got multipleobjecttemplateresponsemixin creates template name www/poll_list.html. name combined prefix generated app_directory loader got /path/to/project/app/templates/www/poll_list.html.

you if don't want have different option (in order):

  • use template_name argument or attribute in view.
  • subclass multipleobjecttemplateresponsemixin , strip out app prefix. mix in views.
  • don't use app_directory loader.

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -