- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Django 3.0.7 并有一个名为 starling
的项目和一个名为 piggybank
的应用程序。我将 index.html
放在 piggybank 目录中的 templates/starling 中以下 urls.py
位于 piggybank
中:
from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
path("", views.index, name="index"),
]
starling(项目)中的urls.py
是:
"""starling URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/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("", include("piggybank.urls")),
path('admin/', admin.site.urls),
]
我的完整settings.py
:
"""
Django settings for starling project.
Generated by 'django-admin startproject' using Django 3.0.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')4^iro*2zhq%f9w2du33eu@ja%)&_cqltplq9b2lzu+qf@xz(6'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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',
]
ROOT_URLCONF = 'starling.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'starling.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
模板加载器事后分析:
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: /home/anna/starling/lib/python3.6/site-packages/django/contrib/admin/templates/starling/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/anna/starling/lib/python3.6/site-packages/django/contrib/auth/templates/starling/index.html (Source does not exist)
最佳答案
要解决此问题,请将 piggybank
添加到设置中的 INSTALLED_APPS
。
在您的 TEMPLATES
设置中,您有:
'APP_DIRS': True,
这是默认设置,意味着 Django 将查看 INSTALLED_APPS
中每个应用程序的 templates
目录。在验尸中你可以看到:
django.template.loaders.app_directories.Loader: /home/anna/starling/lib/python3.6/site-packages/django/contrib/admin/templates/starling/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/anna/starling/lib/python3.6/site-packages/django/contrib/auth/templates/starling/index.html (Source does not exist)
它没有在 piggybank/templates
目录中查找,因为您还没有将 piggybank
添加到 INSTALLED_APPS
中。
关于Django:TemplateDoesNotExist 在/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62191416/
我正在使用 Django 3.0.7 并有一个名为 starling 的项目和一个名为 piggybank 的应用程序。我将 index.html 放在 piggybank 目录中的 template
我有一个看起来很常见的初学者问题。 我正在处理我的第一个 django 项目,当我设置 View 时,出现“TemplateDoesNotExist”错误。 我现在花了很多时间在这上面 - 我知道有很
我可以使用“py manage.py runserver”运行我的服务器,不会出现任何错误,然后我的登录页面出现,我登录到系统,当我单击该页面中的 customer_list 链接时,主欢迎页面会显示
我有以下目录: 项目 模板<-- base.html 位于此处 用户<--应用程序 -- 用户/模板 <-- profile.html 位于此处 profile.html 扩展了 base.html。
我使用的是 Python 3.5 和 Django 1.9。我知道我在某个地方犯了一个愚蠢的错误,但我似乎无法找到它,关于错误可能在哪里的任何帮助? View.py from django.short
Python 2.7 和 Django 1.10我的模板存在,但我做错了! TemplateDoesNotExist at /basicview/2/ TEST This
我正在尝试呈现一个简单的页面,但我遇到了一个问题。 TemplateDoesNotExist at /pages/ {} 找不到模板文件夹。这是我对 settings.py 的配置 BASE_DIR
重要数据: Ubuntu 11.04 Django 1.3.1 我正在运行由 Whoosh 支持的 Haystack。网站的其余部分功能正常,但当我尝试搜索时,我得到一个 TemplateDoesNo
出错了 views.py: def index(request): user = request.user return render(request, 'main_a
我在尝试在 django 中渲染模板时收到此错误: 模板不存在 ... Template-loader postmortem Django tried loading these templates,
我在尝试在 django 中渲染模板时收到此错误: 模板不存在 ... Template-loader postmortem Django tried loading these templates,
我正在尝试在 django 中渲染模板。当我连接到该网站时出现此错误: django.template.loaders.filesystem.Loader: path-to-azerty/templa
我有一个像这样的django实践 │ manage.py ├─accounts │ │ models.py │ │ tests.py │ │ urls.py │ │ views.py
错误 我正在尝试使用 django-nested-inline包裹。似乎一切正常,但是当我尝试使用管理网站创建新的 Course 时,出现以下错误: TemplateDoesNotExist at /
我知道这个网站上有很多关于这个问题的问题,但我找不到解决方案。 我在 Windows 10 上使用 Python 3.6 (anaconda) + django 2.0.2。 我正在学习教程:http
我被这个问题困住了。我在这里和谷歌上检查了很多建议,但没有办法摆脱这个错误。 似乎 Django 没有检查 app/templates/* 目录。它应该自动检查,不是吗? 我的settings.py:
我一直在试用 Django 教程 Django Tutorial Page 3并遇到了这个错误 "TemplateDoesNotExist at /polls/ " . 我假设问题出在我的代码指向模板
我正在使用获取模板的路径 paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') 并在另一个应用
我是Django新手,按照Django官方文档就可以了,但是这里有个问题。 我用 创建了一个新的 Django 项目 Django 1.8.2 + PyCharm 4.5.1 + Python 3.4
我正在尝试在 Django 管理中创建自定义小部件。我创建了一个类: class FroalaWYSIWYGTextareaWidget(django.forms.widgets.Textarea):
我是一名优秀的程序员,十分优秀!