Re: django custom authentication
, 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 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVRJ8Q%2BtThSrUsoB9_zbHZhB0E0jrTavoKrXFTXy5pLMA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: django custom authentication
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. see: https://docs.djangoproject.com/en/1.8/topics/auth/default/#all-authentication-views news: https://docs.djangoproject.com/en/1.8/ref/template-response/#django.template.response.SimpleTemplateResponse.template_name hope can help. On Thursday, September 14, 2017 at 4:58:11 AM UTC+8, yingi keme wrote: > > 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 > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eb518c75-5e5a-486c-9986-74175802eec9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
django custom authentication
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 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/44041d5a-5969-4397-91e1-ba245f68339c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django custom Authentication Backend
Hello everyone I've been trying to create a custom Authentication Backend in Django , It worked .. And it returns an authenticated user and It Logs-in successfuly, BUT , whenever I refresh the page or move for another page it just logout ! it doesn't stuck logged in . here's the backend snap : from django.contrib.auth.models import User class SBAT(ModelBackend): def authenticate(self, username=None, id=None): try : user = User.objects.get(username= username) if user.id == id : return user except : return None def get_user(self ,user_id ): try : user = User.objects.get(pk=user_id) except : return None the login view profile_name = profile_data['name'] profile_id = profile_data['id'] try : user = User.objects.get(username=profile_name+profile_id[:3]) except : user = User.objects.create_user(username=profile_name+profile_id[:3], id = int(profile_id)) user = authenticate(username=user.username , id = int(profile_id) ) login(request,user) return render(request,'index.html') It Login successfully but logout whenever I get out of the current page . Thanks in advance -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/693224b8-ac95-4d3b-9bcd-800544a34087%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django custom authentication
I checked for the session cookie... It is getting created, could it be the django version ? I am using django 1.5 and I found few django openid apps not working on 1.5 . On Tuesday, 22 October 2013 20:44:16 UTC+5:30, Praveen Madhavan wrote: > > Tom > > Thanks for the response, here is my view > > def home(request): > if not request.user.is_authenticated(): > # I have written my own custom authenticate method that returns an > user object > user=authenticate(request=request) > if not user: > return HttpResponseRedirect("/accounts") > else: > login(request,user) > return HttpResponse("Logged in Successfully") > else: > return HttpResponse(request.user) > > > > On Tuesday, 22 October 2013 18:30:13 UTC+5:30, Tom Evans wrote: >> >> On Tue, Oct 22, 2013 at 12:53 PM, Praveen Madhavan >>wrote: >> > Hello All, >> > >> > I am trying custom authentication with django, I wrote a class and >> > filled it with the methods authenticate and get_user, I also added this >> > authentication to the AUTHENTICATION_BACKENDS in settings.py file. >> > >> > I have called my custom authenticate method and followed it up with >> > login in my view. >> >> Show us this view. You should not be calling a "custom authenticate >> method", you should be using login() and authenticate() from >> django.contrib.auth. If you are not, then this explains why on >> subsequent views you are not logged in. >> >> > >> > Everything seems to work fine, is_authenticated returns true for >> the >> > user after login, but the subsequent requests have request.user as >> > anonymous, unable to figure out the reason, require your help >> >> The other cause of login failing is if your browser does not send the >> session cookie back to the server. This would happen if you have >> configured django to send cookies with a different host than the pages >> are served from. Use chrome inspector or firefox or any other tool you >> fancy to determine if this is the case. >> >> The easiest way to see is to look at the session cookie sent with the >> pre-login page response, and the session cookie sent with the >> post-login page response, do they have different ids? >> >> Cheers >> >> Tom >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b447397c-084f-4de1-b498-43b4557d41f6%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django custom authentication
Tom Thanks for the response, here is my view def home(request): if not request.user.is_authenticated(): # I have written my own custom authenticate method that returns an user object user=authenticate(request=request) if not user: return HttpResponseRedirect("/accounts") else: login(request,user) return HttpResponse("Logged in Successfully") else: return HttpResponse(request.user) On Tuesday, 22 October 2013 18:30:13 UTC+5:30, Tom Evans wrote: > > On Tue, Oct 22, 2013 at 12:53 PM, Praveen Madhavan >wrote: > > Hello All, > > > > I am trying custom authentication with django, I wrote a class and > > filled it with the methods authenticate and get_user, I also added this > > authentication to the AUTHENTICATION_BACKENDS in settings.py file. > > > > I have called my custom authenticate method and followed it up with > > login in my view. > > Show us this view. You should not be calling a "custom authenticate > method", you should be using login() and authenticate() from > django.contrib.auth. If you are not, then this explains why on > subsequent views you are not logged in. > > > > > Everything seems to work fine, is_authenticated returns true for the > > user after login, but the subsequent requests have request.user as > > anonymous, unable to figure out the reason, require your help > > The other cause of login failing is if your browser does not send the > session cookie back to the server. This would happen if you have > configured django to send cookies with a different host than the pages > are served from. Use chrome inspector or firefox or any other tool you > fancy to determine if this is the case. > > The easiest way to see is to look at the session cookie sent with the > pre-login page response, and the session cookie sent with the > post-login page response, do they have different ids? > > Cheers > > Tom > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/935a040b-89eb-45cb-9b3e-2e460e64f87f%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django custom authentication
On Tue, Oct 22, 2013 at 12:53 PM, Praveen Madhavanwrote: > Hello All, > > I am trying custom authentication with django, I wrote a class and > filled it with the methods authenticate and get_user, I also added this > authentication to the AUTHENTICATION_BACKENDS in settings.py file. > > I have called my custom authenticate method and followed it up with > login in my view. Show us this view. You should not be calling a "custom authenticate method", you should be using login() and authenticate() from django.contrib.auth. If you are not, then this explains why on subsequent views you are not logged in. > > Everything seems to work fine, is_authenticated returns true for the > user after login, but the subsequent requests have request.user as > anonymous, unable to figure out the reason, require your help The other cause of login failing is if your browser does not send the session cookie back to the server. This would happen if you have configured django to send cookies with a different host than the pages are served from. Use chrome inspector or firefox or any other tool you fancy to determine if this is the case. The easiest way to see is to look at the session cookie sent with the pre-login page response, and the session cookie sent with the post-login page response, do they have different ids? Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1J3Y0qcxen%3D16WoKmVU7bQr0%3DpO0Hjfyq6N-Cwov7McHw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django custom authentication
Praveen I would check that cookies are being returned from the browser, the session information in stored in them, and did you check that get_user() is returning the user corresponding to the ID? François On Oct 22, 2013, at 7:53 AM, Praveen Madhavanwrote: > Hello All, > > I am trying custom authentication with django, I wrote a class and > filled it with the methods authenticate and get_user, I also added this > authentication to the AUTHENTICATION_BACKENDS in settings.py file. > > I have called my custom authenticate method and followed it up with login > in my view. > > Everything seems to work fine, is_authenticated returns true for the user > after login, but the subsequent requests have request.user as anonymous, > unable to figure out the reason, require your help > > > Thanks > Praveen.M > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/b2da7920-4154-4315-b4e7-957c869aa727%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/334003D9-F80D-4A9A-BD62-0C7E618BACBC%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Django custom authentication
Hello All, I am trying custom authentication with django, I wrote a class and filled it with the methods authenticate and get_user, I also added this authentication to the AUTHENTICATION_BACKENDS in settings.py file. I have called my custom authenticate method and followed it up with login in my view. Everything seems to work fine, is_authenticated returns true for the user after login, but the subsequent requests have request.user as anonymous, unable to figure out the reason, require your help Thanks Praveen.M -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b2da7920-4154-4315-b4e7-957c869aa727%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.