django-authentication

Auto-generated field 'user_ptr' clashes with declared field of the same name

余生颓废 提交于 2020-05-29 09:19:06
问题 I have a Django app that has CustomUser. My model looks something like class CustomUser(AbstractBaseUser): def get_short_name(self): pass def get_full_name(self): pass firstName = models.CharField(max_length=300) middleName = models.CharField(max_length=300, blank=True) lastName = models.CharField(max_length=300, blank=True) username = models.CharField(unique=True, max_length=50) businessName = models.CharField(max_length=500, default=None) mobileNumber = models.CharField(max_length=20)

Auto-generated field 'user_ptr' clashes with declared field of the same name

天涯浪子 提交于 2020-05-29 09:18:12
问题 I have a Django app that has CustomUser. My model looks something like class CustomUser(AbstractBaseUser): def get_short_name(self): pass def get_full_name(self): pass firstName = models.CharField(max_length=300) middleName = models.CharField(max_length=300, blank=True) lastName = models.CharField(max_length=300, blank=True) username = models.CharField(unique=True, max_length=50) businessName = models.CharField(max_length=500, default=None) mobileNumber = models.CharField(max_length=20)

Django/Auth: logout clears the session data?

泪湿孤枕 提交于 2020-05-12 19:50:31
问题 I would like to know if auth.logout clears session data or i have to do it by my self. from django.contrib.auth.decorators import login_required from django.contrib import auth @login_required def logout(request): auth.logout(request) return redirect('base:homepage') Something like this... from django.contrib.auth.decorators import login_required from django.contrib import auth @login_required def logout(request): for sesskey in request.session.keys(): del request.session[sesskey] auth.logout

Django auth: Where to put custom templates?

扶醉桌前 提交于 2020-04-14 04:03:12
问题 I want to set up user authentication with Django (1.9). As described in the documentation I included the auth view in my project's urls.py like urlpatterns = [ ..., url('^accounts/', include('django.contrib.auth.urls')), ..., ] as the documentation describes, one needs to write custom templates for the Auth views. I put those templates in the directory myproject/templates/registration/ . The problem is now that these templates, since they follow the predefined naming convention, clash with

Django auth: Where to put custom templates?

巧了我就是萌 提交于 2020-04-14 03:58:05
问题 I want to set up user authentication with Django (1.9). As described in the documentation I included the auth view in my project's urls.py like urlpatterns = [ ..., url('^accounts/', include('django.contrib.auth.urls')), ..., ] as the documentation describes, one needs to write custom templates for the Auth views. I put those templates in the directory myproject/templates/registration/ . The problem is now that these templates, since they follow the predefined naming convention, clash with

'AnonymousUser' object is not iterable

不问归期 提交于 2020-03-18 03:48:29
问题 if not request.user.is_authenticated: return None try: return ClientProfile.objects.get(user=request.user) except ClientProfile.DoesNotExist: return None This code should return None, if I'm not logged in and trying to call it. But as I see from stacktrace, it crashes with error "'AnonymousUser' object is not iterable" on this line: return ClientProfile.objects.get(user=request.user) I'm browsing the following page in private mode, so I'm 100% not authenticated. How to fix this issue? 回答1: In

'AnonymousUser' object is not iterable

帅比萌擦擦* 提交于 2020-03-18 03:48:15
问题 if not request.user.is_authenticated: return None try: return ClientProfile.objects.get(user=request.user) except ClientProfile.DoesNotExist: return None This code should return None, if I'm not logged in and trying to call it. But as I see from stacktrace, it crashes with error "'AnonymousUser' object is not iterable" on this line: return ClientProfile.objects.get(user=request.user) I'm browsing the following page in private mode, so I'm 100% not authenticated. How to fix this issue? 回答1: In

'AnonymousUser' object is not iterable

不想你离开。 提交于 2020-03-18 03:48:09
问题 if not request.user.is_authenticated: return None try: return ClientProfile.objects.get(user=request.user) except ClientProfile.DoesNotExist: return None This code should return None, if I'm not logged in and trying to call it. But as I see from stacktrace, it crashes with error "'AnonymousUser' object is not iterable" on this line: return ClientProfile.objects.get(user=request.user) I'm browsing the following page in private mode, so I'm 100% not authenticated. How to fix this issue? 回答1: In

Django redirect_authenticated_user: True not working

自古美人都是妖i 提交于 2020-02-21 13:30:38
问题 I'm writing an application in Django 1.11. myapp/urls.py pattern looks like from django.conf.urls import url, include from django.contrib import admin from django.contrib.auth.views import LoginView urlpatterns = [ url(r'^login/$', LoginView.as_view(), {'redirect_authenticated_user': True}), url('^', include('django.contrib.auth.urls')), url('^', include('pages.urls')), url(r'^pages/', include('pages.urls')), url(r'^search/', include('search.urls')), url(r'^admin/', admin.site.urls), ] I want

Django redirect_authenticated_user: True not working

半世苍凉 提交于 2020-02-21 13:29:09
问题 I'm writing an application in Django 1.11. myapp/urls.py pattern looks like from django.conf.urls import url, include from django.contrib import admin from django.contrib.auth.views import LoginView urlpatterns = [ url(r'^login/$', LoginView.as_view(), {'redirect_authenticated_user': True}), url('^', include('django.contrib.auth.urls')), url('^', include('pages.urls')), url(r'^pages/', include('pages.urls')), url(r'^search/', include('search.urls')), url(r'^admin/', admin.site.urls), ] I want