在 Django 中找不到模板错误
templets not found error in django
我对 django 模板有点困惑,我附上了工作区的屏幕截图,有人可以告诉我如何在好友应用程序的 views.py 中使用 addprofile.html 模板。
在我的 settings/base.py 中,我通过以下方式提到了模板:
# Build paths inside the project like this: join(BASE_DIR, "directory")
BASE_DIR = dirname(dirname(dirname(__file__)))
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATICFILES_DIRS = [join(BASE_DIR, 'static')]
MEDIA_ROOT = join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
# Use Django templates using the new Django 1.8 TEMPLATES settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
join(BASE_DIR, 'templates'),
# insert more TEMPLATE_DIRS here
join(PROJECT_PATH, 'templates/')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我是 Django 的新手,python 这是我在 Django 中的第一个应用程序
创建以下结构:
buddy (这是您现有的 budy 应用程序文件夹)/templates (这是现有文件夹)/buddy (这是新文件夹) 并放置所有模板:addprofile.html、edit_profile.html、show_profile.html、success.html 在此路径中。
编辑您的设置 'DIRS' 使其看起来如下:
'DIRS': [
join(BASE_DIR, 'templates'),
join(PROJECT_PATH, 'templates/'),
join(BASE_DIR, 'buddy/templates')
我对 django 模板有点困惑,我附上了工作区的屏幕截图,有人可以告诉我如何在好友应用程序的 views.py 中使用 addprofile.html 模板。 在我的 settings/base.py 中,我通过以下方式提到了模板:
# Build paths inside the project like this: join(BASE_DIR, "directory")
BASE_DIR = dirname(dirname(dirname(__file__)))
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATICFILES_DIRS = [join(BASE_DIR, 'static')]
MEDIA_ROOT = join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
# Use Django templates using the new Django 1.8 TEMPLATES settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
join(BASE_DIR, 'templates'),
# insert more TEMPLATE_DIRS here
join(PROJECT_PATH, 'templates/')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我是 Django 的新手,python 这是我在 Django 中的第一个应用程序
创建以下结构:
buddy (这是您现有的 budy 应用程序文件夹)/templates (这是现有文件夹)/buddy (这是新文件夹) 并放置所有模板:addprofile.html、edit_profile.html、show_profile.html、success.html 在此路径中。
编辑您的设置 'DIRS' 使其看起来如下:
'DIRS': [
join(BASE_DIR, 'templates'),
join(PROJECT_PATH, 'templates/'),
join(BASE_DIR, 'buddy/templates')