django-authentication

Django generic login view return 'str object not callable' error

纵然是瞬间 提交于 2019-12-11 20:27:54
问题 My urls.py in myProject is from django.conf.urls import patterns, include, url from testapp import urls urlpatterns = patterns('', url(r'^', include(urls)), ) and my urls.py in myApp (called testapp) is from django.conf.urls import patterns, include, url from testapp.forms import UsersForm urlpatterns = patterns('', url(r'^$', 'django.contrib.auth.views.login', {'template_name': 'testapp/templates/login.html', 'authentication_form':'UsersForm'}), ) My myProject/templates/login.html is <form

Is it possible to make my own createsuperuser command in django?

我怕爱的太早我们不能终老 提交于 2019-12-11 09:57:55
问题 I'm working on an app in which I've made my customized 'User' model which takes email as user name and it is dependent on another model called 'Company' . When running command 'python manage.py createsuperuser' I need that django asks me for company first and create company instance, than asks for User model fields in which 'company' is a foreign key and then user provides company id possibly '1' which the user already created when making company object. I'm trying to implement above by

How to create a user with just First name, Last name and emai. And not with the username

自作多情 提交于 2019-12-11 09:04:56
问题 Is there any way to create a user without the username? I tried doing this by first_name, last_name, password and email. But got an error: TypeError at /accounts/register/ create_user() takes at least 2 arguments (3 given) So, I searched for creating so, and then found that django needs a username. But I hope there is some other way around. Can anyone please guide me through if there is. Thank you. 回答1: If you don't want to use a custom user model you can subclass UserCreationForm and

How to insert default value in database table when user account is created in Django?

不羁的心 提交于 2019-12-11 08:41:40
问题 I am using postgre database have 10 channel in my database. This is my models with channelId and userId as foreign key: class Count(models.Model): userId = models.ForeignKey(User, on_delete=models.CASCADE) channelId = models.ForeignKey(News_Channel, on_delete=models.CASCADE) rate = models.PositiveIntegerField(default=0) def __str__(self): return self.channelId.name class Meta: ordering = ["-id"] I want when a user account is created then 3 row inserted in the table for all 3 channelId and

In Django, how do I write a url.py where users/self/ is the same as users/<pk>/, where <pk> is your logged in user pk?

老子叫甜甜 提交于 2019-12-11 05:19:43
问题 I am trying to write a url.py where I have a simple view for users urlpatterns = patterns( 'doors.view', url( r'^users/$' , 'users_list' , name = 'users_list' ), url( r'^users/(?P<pk>\d+)/$', 'users_detail', name = 'users_detail' ), url( r'^users/self/$' , # do some sort of redirect here ), ) The problem with the redirect is I don't know the pk of the logged in user in url.py . In view.py , I would obviously do a @login_required to be able to access users/self/ . Maybe I am doing this wrong

user.is_authenticated always returns False for inactive users on template

佐手、 提交于 2019-12-11 04:46:21
问题 In my template, login.html , I have: {% if form.errors %} {% if user.is_authenticated %} <div class="alert alert-warning"><center>Your account doesn't have access to this utility.</center></div> {% else %} <div class="alert alert-warning"><center>Incorrect username or password!</center></div> {% endif %} {% endif %} What I am trying to do is, if after form submission, user is inactive then display a different error message and if user is simply not authenticated then display Incorrect

Android-Django user authentication

空扰寡人 提交于 2019-12-11 04:42:25
问题 I am trying to access the current logged in user from the android app in django. but the android application stops unexpectedly giving me fatal exception. the android side code accepts json response when i comment the line at django side i have this code , @login_required def add_healthrecord(request): if request.method=='POST': if not request.user.is_authenticated(): # if user is not logged in response_data=[{"success": "0"}] return HttpResponse(simplejson.dumps(response_data),mimetype=

Django authentication with custom user model with email-id as unique key

不问归期 提交于 2019-12-11 04:06:18
问题 to achieve unique constraint (without repetition of default user models fields) on email-id I did this from django.contrib.auth.models import AbstractUser class User(AbstractUser): # some extra fields class Meta: unique_together = ('email', ) and then in settings file AUTH_USER_MODEL = 'myApp.User' mysql table shows both column(username and email) as UNI key. so far looks good but when it comes to authentication I'm not sure where I'm making mistake. but its not working/loggin-in this code

How to cache user.groups in a request so db isn't hit every time you call request.user.groups.all()?

和自甴很熟 提交于 2019-12-11 03:53:01
问题 I'm using Django with Django REST and have a user permission system based on user groups. As a result I have to check assigned user groups a few times inside views to see if a user belongs to a certain group using request.user.groups.all() . It works but every such call results in an extra query to db to retrieve groups. I wish I could override some method that pulls a user from a db during authentication before attaching it to a request, so I can add something like User.objects.get(pk=userid

Is it possible to change the Hashing algorithm in django_auth?

為{幸葍}努か 提交于 2019-12-11 03:15:04
问题 I have a running wiki with users. Now I want to write an app in Django to do a specific task. I have to use my "old" users/groups database (which has a different hashing algorithm for passwords then django_auth) and sync it every now and then since my users already have a login which has to be the same everywhere. I want to use django_auth as well. Is it possible to change the Hashing algorithm in django_auth? so that django auth uses a function I write to check whether the password inserted