django custom authentication

39 views
Skip to first unread message

yingi keme

unread,
Sep 13, 2017, 4:58:11 PM9/13/17
to Django users
I have this code in my app view

from django.shortcuts import render
from django.contrib.auth.decorators import login_required


@login_required(login_url="login/")
def home(request):
    return render(request, "home.html")


Here also is my project url

from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', include('log.urls')),
    url(r'^login/$', views.login, {'template_name': 'login.html'}),
    url(r'^logout/$', views.logout, {'next_page': '/login'}),
    
]


So i have the templates folder in my project root url and i have also configured TEMPLATES DIR in my settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        ......
        ......
        ......
            ],
        },
    },


However, when i try to access my homepage,i expect it to render my custom login page(login.html). But it always say TemplateDoesNotExist.
I also tried putting the template folder inside an app. But the login page doesnt get rendered still.

I need help urgently.Thanks!!!!

callsa...@gmail.com

unread,
Sep 15, 2017, 4:21:28 AM9/15/17
to Django users
template_name maybe 
  • template_name: The name of a template to display for the view used to log the user in. Defaults to registration/login.html.


hope can help.

James Schneider

unread,
Sep 15, 2017, 5:40:30 AM9/15/17
to django...@googlegroups.com, Andy
,


However, when i try to access my homepage,i expect it to render my custom login page(login.html). But it always say TemplateDoesNotExist.
I also tried putting the template folder inside an app. But the login page doesnt get rendered still.

I need help urgently.Thanks!!!!

The error page should list all of the locations where the template engine searched, and the name of the file it was looking for (assuming DEBUG=True). Make sure the file exists in one of those locations, and that the user running the Django server process (probably yours if using runserver locally) has access to read the file.

With out the traceback or any of the specific error information, there isn't much more anyone can tell you.

-James
Reply all
Reply to author
Forward
0 new messages