Ad

Django 1.9 And Registration/login.html

- 1 answer

I'm working on a django 1.9 project.

With Django 1.7.7, login functionnalities was working, but now all the time I have : registration/login.html : Template Does Not Exist

The templates login.html, logout.html are present in 'webgui/template/registration/' and I didn't modified them.

Here some of my settings.py :

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'webgui',
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'project.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',
        ],
    },
},
]

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'NCIS.db'),
}
}

STATIC_URL = '/static/'
LOGIN_REDIRECT_URL = '/login/'

LOGOUT_URL = '/logout/'


DIRS = (
    join(BASE_DIR, 'webgui/template/registration'),
    join(BASE_DIR, 'webgui/template/')
)

And my urls.py :

from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.views import login, logout
import webgui.views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', login, name='login.html'),
    url(r'^login/$', login, name='login.html'),
    url(r'^logout/$', logout, name='logout.html'),

    url(r'^homepage/$', webgui.views.homepage),
    url(r'^addproject/$', webgui.views.addproject)
]

What's wrong? I checked the Django docs, but that's the default behaviour.

Ad

Answer

Try to put your template dirs paths in DIRS list inside TEMPLATES setting. (Anyway, your template folder name should be templates not template.)

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [join(BASE_DIR, 'webgui/template/registration'),join(BASE_DIR, 'webgui/template/')],
    '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',
        ],
    },
},
]
Ad
source: stackoverflow.com
Ad