Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django 1.9 and registration/login.html

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.

like image 435
Isador Avatar asked Feb 09 '16 11:02

Isador


People also ask

Can we connect Django with HTML?

In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let's do that. Create a templates folder inside the members folder, and create a HTML file named myfirst.html .

How do I login as user in Django?

from django.contrib.auth import authenticate, login def my_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) # Redirect to a success page. ... else: # Return an 'invalid ...


2 Answers

This question appears first in search engine with searching for registration/login.html : Template Does Not Exist

So for those coming through search engine, please note that this template doesn't come by default with Django. If you haven't created it, that's why you are getting this error

Here is how you can create a simple one https://simpleisbetterthancomplex.com/tutorial/2016/06/27/how-to-use-djangos-built-in-login-system.html

like image 114
Ramast Avatar answered Oct 13 '22 01:10

Ramast


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',
        ],
    },
},
]
like image 45
doru Avatar answered Oct 13 '22 01:10

doru