django-authentication

How to programmably create an User in Django?

How to programmably create an User in Django? Question: I have 3 apps in one project. App1 : use from enduser(web view based app) App2 : use from service provider(web service) App3 : use from system administrator. I want to use django authentication system for each apps. I can make django project to authenticate App1’s …

Total answers: 2

Django – Login with Email

Django – Login with Email Question: I want django to authenticate users via email, not via usernames. One way can be providing email value as username value, but I dont want that. Reason being, I’ve a url /profile/<username>/, hence I cannot have a url /profile/[email protected]/. Another reason being that all emails are unique, but it …

Total answers: 18

Log in user using either email address or username in Django

Log in user using either email address or username in Django Question: I am trying to create an auth backend to allow my users to log in using either their email address or their username in Django 1.6 with a custom user model. The backend works when I log in with a user name but …

Total answers: 16

django – set user permissions when user is automatically created using get_or_create

django – set user permissions when user is automatically created using get_or_create Question: Django 1.5, python 2.6 The model automatically creates a user under certain conditions: User.objects.get_or_create(username=new_user_name, is_staff=True) u = User.objects.get(username=new_user_name) u.set_password(‘temporary’) In addition to setting the username, password, and is_staff status, I would like to set the user’s permissions – something like: u.user_permissions(‘Can view …

Total answers: 3

Django unit test; Login using python-social-auth

Django unit test; Login using python-social-auth Question: I would like to write unit tests for my Django app that is using python-social-auth. It all works great when running Django and using a browser, thanks python-social-auth! However, I can’t seem to write unit tests because I can’t create an authenticated client to test with. Has anyone …

Total answers: 3

How to use TokenAuthentication for API in django-rest-framework

How to use TokenAuthentication for API in django-rest-framework Question: I have a django project, using django-rest-framework to create api. Want to use token base authentication system so api call for (put, post, delete) will only execute for authorized user. I installed ‘rest_framework.authtoken’ and created token for each users. So, now from django.contrib.auth.backends authenticate, it returns …

Total answers: 4

How to get user permissions?

How to get user permissions? Question: I want to retrieve all permission for user as list of premission id’s but: user.get_all_permissions() give me list of permission names. How to do it? Asked By: Nips || Source Answers: The key is get the permission objects like this: from django.contrib.auth.models import Permission permissions = Permission.objects.filter(user=user) and there …

Total answers: 8

AttributeError: 'Manager' object has no attribute 'get_by_natural_key' error in Django?

AttributeError: 'Manager' object has no attribute 'get_by_natural_key' error in Django? Question: I am using Django ‘1.5c1’. I have this line in my settings.py: AUTH_USER_MODEL = ‘fileupload.galaxyuser’ Here’s my Galaxyuser model: class GalaxyUser(models.Model): id = models.IntegerField(primary_key=True) create_time = models.DateTimeField(null=True, blank=True) update_time = models.DateTimeField(null=True, blank=True) email = models.CharField(max_length=765) password = models.CharField(max_length=120) external = models.IntegerField(null=True, blank=True) deleted = …

Total answers: 4

In Django, how do I check if a user is in a certain group?

In Django, how do I check if a user is in a certain group? Question: I created a custom group in Django’s admin site. In my code, I want to check if a user is in this group. How do I do that? Asked By: TIMEX || Source Answers: You can access the groups simply …

Total answers: 13

Change Django ModelChoiceField to show users' full names rather than usernames

Change Django ModelChoiceField to show users' full names rather than usernames Question: I have a form in my Django app (not in admin) that allows staff members to select a user from a dropdown. forms.ModelChoiceField(queryset = User.objects.filter(is_staff=False), required = False) The problem is that the dropdown shows users by usernames whereas I’d rather it show …

Total answers: 5