python - django 模板不存在于

标签 python django

我得到了

templatedoesnotexistat / login.html

我从另一个有效的项目中复制并粘贴了设置,但无法弄清楚为什么它找不到模板文件。我已经检查了很多次并复制了路径,所以它们应该是正确的。这让我发疯

我的文件结构是

-virtual
    -src
    -logins
    -dashboards
    -static
        -templates
            -login.html
        -static
        -static-only
        -media

设置.py

import os
BASE_DIR = '/Users/user/Documents/Python/virtual/'

DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'logins',
    'dashboards',
)

ROOT_URLCONF = 'src.urls'

STATIC_URL = '/static/'

TEMPLATE_DIR = (
    '/Users/user/Documents/Python/virtual/src/static/templates',
)

if DEBUG:
    MEDIA_URL = '/media/'
    STATIC_ROOT = '/Users/user/Documents/Python/virtual/src/static/static-only/'
    MEDIA_ROOT = '/Users/user/Documents/Python/virtual/src/static/media/'
    STATICFILES_DIRS = (
        '/Users/user/Documents/Python/virtual/src/static/static/',
    )

url.py

from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'logins.views.login', name='login'),
    url(r'^/accounts/auth/$', 'logins.views.auth_view', name='auth_view'),
    url(r'^/accounts/dashboard/$', 'dashboards.views.dashboard', name='dashboard'),
    url(r'^/accounts/logout/$', 'logins.views.logout', name='logout'),
    url(r'^/accounts/invalid/$', 'logins.views.invalid', name='invalid'),

    url(r'^admin/', include(admin.site.urls)),
)

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View .py

from django.shortcuts import render, render_to_response, RequestContext
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf

def login(request):
    c = {}
    c.update(csrf(request))
    return render_to_response('login.html', c)

def auth_view(request):
    username = request.POST.get('username', '')
    password = request.POST.get('password', '')
    user = auth.authenticate(username=username, password=password)

    if user is not None:
        auth.login(request, user)
        return HttpResponseRedirect('/accounts/dashboard')
    else:
        return HttpResponseRedirect('/accounts/invalid')

def logout(request):
    return render_to_response('logout.html')

def invalid(request):
    return render_to_response('invalid.html')

最佳答案

您的设置中有TEMPLATE_DIR。它应该是TEMPLATE_DIRS

关于python - django 模板不存在于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25595638/

相关文章:

python - 更改 Numpy 数组第 0 行中的值

python - 在python中将多个字典转换为单个字典

python - 如何告诉 Python 不要解释字符串中的反斜杠?

python - 如何在管理中的django modelform中访问request.user

python - 在 Django 中使用 clean() 方法

python - 套接字对和 fork 中的 FD 重用

python - 如何理解 python numpy 数组中的空维度?

python - Tensorflow Estimator API 在评估模式下保存图像摘要

Django 基于类的 View : How to check an object value before returning view

python - images/create 处的类型错误 - __init__() 获得意外的关键字参数 'save'