[英]Why is Django (3.0.6) looking in the wrong directory for admin static files?
[英]Django looking in wrong directory for templates
我遵循了一个教程,该教程教您按照~/project/main/templates/main
顺序构建模板目录,以避免和造成混淆。 现在,我正在尝试创建另一个项目,并使用与最佳实践相同的结构。 尝试渲染位于/home/arch/project/main/templates/main/index.html
html时出现TemplateDoesNotExist错误,它表示Django正在/home/arch/project/templates/main/index.html
中/home/arch/project/templates/main/index.html
settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
main / views.py
from django.shortcuts import render, redirect
def homepage_view(request):
return render(request, "main/index.html")
main / urls.py
from django.urls import path
from . import views
app_name = "main"
urlpatterns = [
path("", views.homepage_view, name="homepage_view")
]
我项目的结构
.
├── db.sqlite3
├── main
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── templates
│ │ └── main
│ │ ├── includes
│ │ └── index.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
├── media
├── project
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── settings.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── wsgi.cpython-37.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── static
检查您的应用是否已添加到INSTALLED_APPS
。 第一次尝试Django时遇到了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.