我試圖在 Django 中設定我的第一個簡單 CBV,但是盡管閱讀了所有相關資訊并嘗試了所有可能的 index.html 路徑選項,但我從上面收到了相同的訊息。最新版本如下:
Python 版本:3.9.13 Django:4.1
**urls.py**
from django.urls import path
from core.views import Servicelist
urlpatterns = [
path('', Servicelist.as_view(), name='service')
]
**views.py**
from core.models import Item
from django.views.generic.list import ListView
class Servicelist(ListView):
model = Item
template_name:'paraticosmetics/index.html'
context_object_name = "items"
I receive message that index is not defined Pylance(reportundefinedVariable)
**setting.py**
**setting.py**
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'core.apps.CoreConfig',
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR/'core/templates/paraticosmetics/'],
"APP_DIRS": True,
....
uj5u.com熱心網友回復:
template_name:'paraticosmetics/index.html'
這一行可能是您需要=的問題(變數賦值)而不是:(型別定義)
如果沒有,請向我們展示 的值BASE_DIR,TEMPLATES以及您的專案的目錄結構。
uj5u.com熱心網友回復:
你的應用程式被稱為“paraticosmetics”嗎?嘗試將其添加到您的 INSTALLED_APPS 串列中
'core.apps.CoreConfig',
'paraticosmetics',
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/516456.html
標籤:python-3.xdjango列表显示django-模板
