# TemplateDoesNotExist at /new\_topic/

**URL:** <https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285>\
**Category:** Getting Started\
**Created:** [August 22, 2023, 11:33pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285 "2023-08-22T23:33:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![swydell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/swydell/32/15520_2.png) [@swydell](https://forum.djangoproject.com/u/swydell)\
**Post date:** [August 22, 2023, 11:33pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/1 "2023-08-22T23:33:12Z")

</div>

I’m working out of a text book Python Crash Course third edition in chapters 18 and 19. I writing the code word for word line by line. I believe my issue is in views.py. When I run python manage.py runserver the browser opens to localhost:8000. But when I try to click on new topic link I get the error above. Here is my views.py code

# from django.http import HttpResponseRedirect

#from importlib.metadata import EntryPoints, entry\_points  
from django.shortcuts import render, redirect  
#from pkg\_resources import EntryPoint

# Create your views here.

from .models import Topic, Entry  
from .forms import TopicForm, EntryForm

def index(request):  
“”“The home page for learning Log.”“”  
return render(request, ‘learning\_logs/index.html’)

def topics(request):  
“”“Show all topics.”“”

```
topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/topics.html', context)

```

def topic(request, topic\_id):  
“”“Show a single topic and all its entries.”“”  
topic = Topic.objects.get(id=topic\_id)  
entries = topic.entry\_set.order\_by(‘-date\_added’)  
context = {‘topic’: topic, ‘entries’: entries}  
return render(request, ‘learning\_logs/topic.html’, context)

def new\_topic(request):  
“”“Add a new topic”“”  
if request.method != ‘POST’:  
# No data submitted; create a blank form.  
form = TopicForm()  
else:  
# POST data submitted; process data.  
form = TopicForm(data=request.POST)  
if form.is\_valid():  
form.save()  
return redirect(‘learning\_logs:topics’)  
# Display a blank or invalid form.  
context = {‘form: form’}  
return render(request, ‘learning\_logs/new\_topic.html’, context)

def new\_entry(request, topic\_id):  
“”“Add a new entry for a particular topic.”“”  
topic = Topic.objects.get(id=topic\_id)

```
if request.method != 'POST':
# No data submitted; create a blank form.
    form = EntryForm()
else:
    # POST data submitted; process data.
    form = EntryForm(data=request.POST)
    if form.is_valid():
        new_entry = form.save(commit=False)
        new_entry.topic = topic
        new_entry.save()
        return redirect('learning_logs:topic', topic_id=topic_id)

```

def edit\_entry(request, entry\_id):  
“”“Edit an existing entry.”“”  
entry = Entry.objects.get(id=entry\_id)  
topic = entry.topic

```
if request.method !='POST':
    # Initial request; pre-fill form with current entry.
    form = EntryForm(instanc=entry)
else:
    # Post data submitted; process data.
    form = EntryForm(instance=entry, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect('learning_logs:topic', topic_id=topic.id)
               
# Display a blank or invalid form.
context = {'entry': entry, 'topic': topic, 'form': form}
return render(request, 'learning_logs/edit_entry.html', context)

```

Here is my learning\_logs/urls code

> Blo"““Define URL patterns for learning\_logs.””"

from django.urls import path

from . import views

app\_name = ‘learning\_logs’  
urlpatterns = [  
# Home page  
path(‘’, views.index, name=“index”),  
# Page that shows all topics.  
path(‘topics/’, views.topics, name=‘topics’),

```
# Detail page for a single topic.
path('topics/<int:topic_id>/', views.topic, name='topic'),
# Page for adding a new topic,\
path('new_topic/', views.new_topic, name='new_topic'),

# Page for adding a new entry
path('new_entry/<int:topic_id>/', views.new_entry, name='new_entry'),

# page for editing an entry.
path('edit_entry/<int:entry_id>/', views.edit_entry, name='edit_entry'),

```

]ckquote

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 23, 2023, 12:37am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/2 "2023-08-23T00:37:08Z")

</div>

A couple things -

- When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. Do this for each file that you’re posting here.

- There’s more information that gets printed than just the name of the error. Whenever you’re asking for help here, always include the complete error, including the full traceback. (Also, surround this information between lines of ``` just like the code.)

- Show your directory structure, including the location of your template files.

- Post your TEMPLATES setting from your settings.py file.

---

<div class="post-metadata">

**Author:** ![ealalin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ealalin/32/17520_2.png) [@ealalin](https://forum.djangoproject.com/u/ealalin)\
**Post date:** [January 2, 2024, 10:46pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/3 "2024-01-02T22:46:07Z")

</div>

‘’’ I have a similar problem ‘’’  
‘’’ my deposal directory for my html files is C:\learning\_log\learning\_logs\templates\learning\_logs’‘’  
‘’’ Directory of C:\learning\_log\learning\_logs\templates\learning\_logs

31/12/2023 22:41 .  
31/12/2023 22:41 …  
31/12/2023 23:29 147 base.html  
31/12/2023 22:51 182 index.html  
01/01/2024 22:58 265 topics.html ‘’’

‘’’ My topics.html

{% extends “learning\_logs/base.html” %}

{% block content %}

Topics

 {% for topic in topics %} - {{ topic }}
 {% empty %} - No topics have been added yet.
 {% endfor %} 
{% endblock content %}

‘’’

‘’’ My views.py ‘’’

“”" From learning\_log/learning\_logs “”"  
from django.shortcuts import render  
from .models import Topic  
‘’‘# Create your views here.’‘’

def index(request):  
“”" the home page from learning\_log “”"  
return render(request, ‘learning\_logs/index.html’)

‘’’ #def topics(request):  
‘’‘# show all topics’‘’  
‘’‘# topics = Topic.objects.order\_by(‘date\_added’) #date\_added’‘’  
‘’‘# context = {‘topics’:topics}’‘’  
‘’‘# return render(request,‘learning\_logs/topics.html’, context)’‘’

‘’‘# ADD test 01/01/2024’‘’  
def topics(request):  
“”“show all topics”“”  
topics = Topic.objects.order\_by(‘date\_added’)  
print(topics) # Add this line for debugging  
context = {‘topics’: topics}  
return render(request, ‘learning\_logs/topics.html’, context)

‘’’ The runserver find the data requested (200) ‘’’

‘’’ C:\learning\_log\>python manage.py runserver  
Watching for file changes with StatReloader  
Performing system checks…

System check identified no issues (0 silenced).  
January 02, 2024 - 21:52:08  
Django version 3.2.18, using settings ‘learning\_log.settings’  
Starting development server at [http://127.0.0.1:8000/](http://127.0.0.1:8000/)  
Quit the server with CTRL-BREAK.  
\<QuerySet [\<Topic: Topic 1\>, \<Topic: Topic 2\>]\>  
[02/Jan/2024 21:52:23] “GET /topics/ HTTP/1.1” 200 86  
,  
‘’’ but the display on my browser is

[learning\_logs](http://127.0.0.1:8000/) - [topics](http://127.0.0.1:8000/topics/)" }‘’’

![Chrome](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/3/6/36ae2b6f5a1f7506848b72dd6e8b17431fbcd73a.png)

‘’’ My setting.py contain ‘’’

TEMPLATES = [  
{  
‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’,  
‘DIRS’: ,  
‘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’,  
],  
},  
},  
]

‘’’ seams that the data base is working fine

C:\learning\_log\>python manage.py shell  
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32  
Type “help”, “copyright”, “credits” or “license” for more information.  
(InteractiveConsole)

> > > from learning\_logs.models import Topic  
> > > first\_topic = Topic.objects.first()  
> > > print(first\_topic)  
> > > Topic 1  
> > > specific\_topic = Topic.objects.get(id=1)  
> > > print(specific\_topic)  
> > > Topic 1 ‘’’

‘’’ Seams that django does not find his views.py to display the informations to the browser screen ‘’’

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 2, 2024, 10:49pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/4 "2024-01-02T22:49:43Z")

</div>

First, I’d suggest you open a new topic for this discussion since this may well be a different issue.

Also, note that you need to use the backtick - ` to mark off your code blocks, with the three backtick characters on a line by themselves before and after the block of code. It’s a line of ```, then the code, then another line of ```. The ``` must not be part of the same line as any other text. Make sure you use the backtick and not the apostrophe - ' or any other “smart quote” from a word processor/text editor.

---

<div class="post-metadata">

**Author:** ![ealalin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ealalin/32/17520_2.png) [@ealalin](https://forum.djangoproject.com/u/ealalin)\
**Post date:** [January 2, 2024, 11:31pm UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/5 "2024-01-02T23:31:03Z")

</div>

Ok ken , I will do it . sorry for the wrong format.

Best regards and beste wishes for 2024

---

<div class="post-metadata">

**Author:** ![Treelover01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/treelover01/32/21089_2.png) [@Treelover01](https://forum.djangoproject.com/u/Treelover01)\
**Post date:** [May 6, 2024, 12:42am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/6 "2024-05-06T00:42:21Z")

</div>

Having that problem now. Ever figure this out?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 6, 2024, 12:45am UTC](https://forum.djangoproject.com/t/templatedoesnotexist-at-new-topic/23285/7 "2024-05-06T00:45:15Z")

</div>

Welcome @Treelover01 !

If you are having a problem with which you would like assistance, please open a new topic for the discussion and include all the relevent details.
