why I am unable to see topics at my project python crash course

186 views Asked by At

python crash course I am trying to continue with chapter 18, getting started with Django learning_logs project, once I try to run topics shows this message

Environment:

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

Django Version: 3.0.5
Python Version: 3.7.1
Installed Applications:
['learning_logs',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
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']
Traceback (most recent call last):
  File "C:\learning_log\ll_env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\learning_log\ll_env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\learning_log\ll_env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\learning_log\learning_logs\views.py", line 14, in topics
    return render (request, 'learning_logs/topics.html', context)

Exception Type: NameError at /topics/
Exception Value: name 'context' is not defined

Exception Location: C:\learning_log\learning_logs\views.py in topics, line 14

my views.py

from django.shortcuts import render
from django.template import Context

from .models import Topic

def index(request):
    """the home page for learning log."""
    return render(request, 'learning_logs/index.html')pyht

def topics(request):
    """show all topics."""
    topics = Topic.objects.order_by('date_added') 
    contex = {'topics': topics}
    return render (request, 'learning_logs/topics.html', context)
1

There are 1 answers

2
sahasrara62 On

return render(request, 'learning_logs/index.html')pyht this should be return render(request, 'learning_logs/index.html')

Typo error