python - Django 2 : TemplateDoesNotExist even if files placed properly

标签 python django django-templates

我在 Django 2 上遇到了有趣的问题。

在我的 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',
            ],
        },
    },
]

之后,我在我的项目根文件夹中创建了文件夹 templates

然后我创建了名为 front 的应用程序并将其添加到我的 settings.py INSTALLED_APPS:

app_image

在我的 views.py 中,我添加了这个 View :

def index(request):
    return render(request, 'front/index')

我已经像这样分配了它的 url:

url(r'^$', views.index, name='index'),

当我尝试访问此 View 时出现此错误:

TemplateDoesNotExist at /
front/index

为什么会这样?我错过了什么吗?

最佳答案

改变

def index(request):
    return render(request, 'front/index')

def index(request):
    return render(request, 'front/index.html')

关于python - Django 2 : TemplateDoesNotExist even if files placed properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48864957/

相关文章:

python - 要在应用程序之间共享的自定义对象管理器应该放在哪里?

Django NoReverseMatch at/services/'services' 不是注册的命名空间

python - 如果不是之前和之后的正则表达式匹配

python - 随机访问可重新创建的随机生成的大数据

python - PCA:获取前 20 个最重要的维度

python - DRF 序列化器通过 REST API 与第三方应用程序进行操作

python - Django 按最新评分列出所有作者

django-templates - 在 Django 模板中直接使用 GET 和 POST 变量

python - 如何将自定义元素列表正确传递给类属性?

python - keras 有状态 LSTM