为什么我在我的项目python速成班上 看不到主题

问题描述 投票:0回答:1

Python崩溃课程,我试图继续阅读第18章,开始尝试Django learning_logs项目,一旦我尝试运行主题,就会显示此消息

环境:

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

主题中第14行的异常位置:C:\ learning_log \ learning_logs \ views.py

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)
python url
1个回答
0
投票

[return render(request, 'learning_logs/index.html')pyht这应该是return render(request, 'learning_logs/index.html')

拼写错误

© www.soinside.com 2019 - 2024. All rights reserved.