Ошибка имени в django имя 'index' не определено - PullRequest
0 голосов
/ 23 марта 2020

Я создаю музыкальный веб-сайт c.

Я получаю ошибку:

NameError at /
name 'index' is not defined
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 2.2.5
Exception Type: NameError
Exception Value:    
name 'index' is not defined
Exception Location: E:\coding\fyp\travel\app1\views.py in cities, line 20
Python Executable:  D:\anacondapython3\python.exe
Python Version: 3.7.4
Python Path:    
['E:\\coding\\fyp\\travel',
    'D:\\anacondapython3\\python37.zip',
    'D:\\anacondapython3\\DLLs',
    'D:\\anacondapython3\\lib',
    'D:\\anacondapython3',
    'D:\\anacondapython3\\lib\\site-packages',
    'D:\\anacondapython3\\lib\\site-packages\\win32',
    'D:\\anacondapython3\\lib\\site-packages\\win32\\lib',
    'D:\\anacondapython3\\lib\\site-packages\\Pythonwin']
Server time:    Mon, 23 Mar 2020 15:51:04 +0000
Traceback Switch to copy-and-paste view
    D:\anacondapython3\lib\site-packages\django\core\handlers\exception.py in 
 inner
        response = get_response(request) …
▶ Local vars
    D:\anacondapython3\lib\site-packages\django\core\handlers\base.py in 
      _get_response
            response = self.process_exception_by_middleware(e, request) …
 ▶ Local vars
D:\anacondapython3\lib\site-packages\django\core\handlers\base.py in 
   _get_response
            response = wrapped_callback(request, *callback_args, 
     **callback_kwargs) …
 ▶ Local vars
    E:\coding\fyp\travel\app1\views.py in cities
        return render(request,index.html,{'dests':dests}) …
  ▶ Local vars

Мои путешествия urls.py выглядят так:

"""travel URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('app1.urls'))
]

my app1 urls.py:

"""travel URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('app1.urls'))
]

my app1 views.py:

from django.shortcuts import render
from .models import Destination
# Create your views here.
def cities(request):
    dest1=Destination()
    dest1.name='california'
    dest1.dest='the city that never sleeps'
    dest1.price=750
    dest2=Destination()
    dest2.name='LA'
    dest2.dest='the peaceful city'
    dest2.price=800
    dest3=Destination()
    dest3.name='washington'
    dest3.dest='the operating city'
    dest3.price=650
    dests=[dest1,dest2,dest3]
    return render(request,index.html,{'dests':dests})

Пожалуйста, помогите мне.

1 Ответ

0 голосов
/ 23 марта 2020

Как сказал Иэн Шелвингтон, индекс имени вашего шаблона. html в последней строке должен быть в кавычках, поскольку он не является переменной

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...