Please Help With LearnDjango Slug Tutorial

Happy New Year to all of You great folks. Please help. I am getting a TemplateDoesNotExist at /1 error message. I am working on LearnDjango Slug Tutorial.

I have created both the article_list.html and the article_detail.html templates. When I run the server the list of articles comes out good and proper. The tutorial says I should be able to get the detail if I run

And the detail view for our single article is at http://127.0.0.1:8000/1.

However when I run this command I get the TemplateDoesNotExist at /1 error. What am I missing here? Or what should I not be doing that is making me get this error. Thanks for your patience and understanding.

1 Like

The direct answer is that you don’t have the requested template created in the appropriate directory. Without seeing your code or the directory structure containing the templates, we can’t get any more specific than that.

Please post the complete error with the traceback as it appears in your runserver console window.

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/1

Django Version: 5.1.4
Python Version: 3.12.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'articles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template loader postmortem
Django tried loading these templates, in this order:

Using engine django:
    * django.template.loaders.app_directories.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\contrib\admin\templates\article_detail.html] (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\contrib\auth\templates\article_detail.html] (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\articles\templates\article_detail.html] (Source does not exist)



Traceback (most recent call last):
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\core\handlers\base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\template\response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\template\response.py", line 90, in rendered_content
    template = self.resolve_template(self.template_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\template\response.py", line 72, in resolve_template
    return select_template(template, using=self.using)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ZACKAMATA\Documents\Learn Python\Django\LearnDjango\newspaper\venewspaper\Lib\site-packages\django\template\loader.py", line 47, in select_template
    raise TemplateDoesNotExist(", ".join(template_name_list), chain=chain)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: TemplateDoesNotExist at /1
Exception Value: article_detail.html]

This error message is telling you that it’s looking for the file article_detail.html in these locations:

But the file does not exist in one of those directories.

I have the articles app. Inside of this directory I have a templates directory. Like so:- NEWSPAPER
-articles
–templates
—articles
----article_detail.html
----article_list.html
-djangoProject

From your observation I will try move the two html files back up to the templates directory. Let me see if that works. Thanks for your help

Wow! Wow!! Wow!!!. Hey Ken thanks ever so much. It worked. It really worked. I moved the html files from the articles directory in the app-level articles directory up to the templates directory. And what do you know it worked. Thanks.

2 Likes