Django tutorial - Misleading instructions

36 views
Skip to first unread message

Justin Stubbs

unread,
Jun 29, 2017, 9:54:27 PM6/29/17
to Django users
Hi Guys,

Im following the tutorial https://docs.djangoproject.com/en/1.11/intro/tutorial03/ and have found that the section on templates doesn't appear to be correct.

The section talks about how django templates are loaded by default if you put them in the correct path:





def auth(request):
return render(request, 'g_auth/index.html')



but when I used a similar example django complained about not being able to find the templates. I ended up having to change the django settings file 'DIRS':

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'g_auth/templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


Hoping to get this clarified as for a beginner this would be quite complicated(assuming I haven't missed the boat completely here)

Cheers,

Justin

Tim Graham

unread,
Jun 29, 2017, 10:07:37 PM6/29/17
to Django users
The 'g_auth/templates' directory should be searched because of 'APP_DIRS': True. Is 'g_auth' in INSTALLED_APPS?

ecas

unread,
Jun 30, 2017, 6:54:01 AM6/30/17
to Django users
As Tim said, the APP_DIRS flag enables the app template loader.

https://docs.djangoproject.com/en/1.11/ref/templates/api/#django.template.loaders.app_directories.Loader

"Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there."



El divendres, 30 juny de 2017 3:54:27 UTC+2, Justin Stubbs va escriure:
Reply all
Reply to author
Forward
0 new messages