Reverse for 'topics' not found. 'topics' is not a valid view function or pattern name
<p>
<a href="{% url 'learning_logs:index' %}">Learning Log</a>
<a href="{% url 'learning_logs:topics' %}">Topics</a>
</p>
{% block content %}{% endblock content %}
I get that error: Reverse for 'topics' not found. 'topics' is not a valid view function or pattern name. at this line:
<a href="{% url 'learning_logs:topics' %}">Topics</a>
Here I creat views:
from django.shortcuts import render
from .models import Topic
# Create your views here.
def index(request):
"""Main page for app Learning Logs"""
return render(request, 'learning_logs/index.html')
# A view of topics
def topics(request):
topics = Topic.objects.order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/topics.html', context)
def topic(request, topic_id):
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)
Here is a template of topics:
{% extends "learning_logs/base.html" %}
{% block content %}
<p>
Topics
</p>
<ul>
<!--this is a for loop which iterates through topics-->
{% for topic in topics %}
<li>
<a href = "{% url 'learning_logs:topic' topic.id %}">{{ topic }}</a>
</li>
{% empty %}
<li>No topic has been added yet</li>
</ul>
{% endblock content %}
I am new to Django and I don't understand why this problem appeared.