django-authentication

how to get group name using User in django

随声附和 提交于 2021-02-20 04:47:28
问题 I am stuck in django's group module can any one tell me how to solve it. my problem is now i'm dispalying the username of the logged-in user, i want to display group-name and the profiles present in that group along with the username.and my views are like this, def user(request): context = {'user': request.user} return render_to_response('username.html', context, context_instance=RequestContext(request)) now what do I need to add in order to achieve my requirement forms.py class LoginForm

Django 2.1.2 Password reset auth view: Reverse for 'password_reset_confirm' not found

安稳与你 提交于 2021-02-17 05:33:23
问题 I am having a problem with the passeord reset system. The code is as below. When I enter the respective URL into the browser address directly it shows the expected Django forms/pages. However if I fill an email address and hit enter/click the link, I get the "Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name." error at line 6 in password_reset_email.html. But I have included the uid64! and the token! Also, when I deliberately

Check admin login on my django app

偶尔善良 提交于 2021-02-11 18:06:49
问题 I have created a django app and have linked to the admin index page by modifying base.html. However, the link of the app is accessible directly as well. Can I check on the page or in the views.py of my app if the user is logged in to the django admin or not? 回答1: Use the @staff_member_required decorator: from django.contrib.admin.views.decorators import staff_member_required @staff_member_required def my_view(request): ... 回答2: from django.contrib.auth.decorators import user_passes_test @user

Check admin login on my django app

时光毁灭记忆、已成空白 提交于 2021-02-11 18:04:09
问题 I have created a django app and have linked to the admin index page by modifying base.html. However, the link of the app is accessible directly as well. Can I check on the page or in the views.py of my app if the user is logged in to the django admin or not? 回答1: Use the @staff_member_required decorator: from django.contrib.admin.views.decorators import staff_member_required @staff_member_required def my_view(request): ... 回答2: from django.contrib.auth.decorators import user_passes_test @user

How do I get the Django login api to work after extending the user object?

独自空忆成欢 提交于 2021-02-10 18:15:37
问题 I've followed the documentation here to extend my user class, but now my login tests fail. I'm assuming this is due to the extended class not being linked correctly back to the django view that deals with auth. r = self.client.post('/login/', {'username': 'test@test.com', 'password': 'test'}) returns b'\n<!doctype html>\n<html lang="en">\n<head>\n <title>Not Found</title>\n</head>\n<body>\n <h1>Not Found</h1><p>The requested resource was not found on this server.</p>\n</body>\n</html>\n' I've

Why does django have both an authenticate method and a login method?

↘锁芯ラ 提交于 2021-02-10 14:13:52
问题 I'm going through an authentication tutorial and the author is using the authenticate() method to authenticate the credentials data from a login form. The result is assigned to a user variable like so user = authenticate(username=username, password=password) next: The user is logged in using login(request, user) But why the 2 different methods? Isn't authenticating credentials supposed to be part of the procedure of loggin in? So why isn't that part handled by the login function as well? Or

Sending emails when a user is activated in the Django admin

廉价感情. 提交于 2021-01-27 08:25:15
问题 I'm about to create a site that has monitored registration in that only certain people are allowed to register. Undoubtedly some misfits will register despite any writing I put above the registration form so we're going with moderation. Upon registration a django.contrib.auth User and profile will be created and an email will be sent to the moderator. The moderator will log into the Django admin site, check they're somebody who is allowed to register and mark their account active. If they're

Register custom user model with admin auth

孤街醉人 提交于 2021-01-21 06:22:02
问题 In a Django project, I have a custom user model that adds one extra field: class User(AbstractUser): company = models.ForeignKey(Company, null=True, blank=True) This model is defined in my app, say MyApp.models . How can I get the new User model to show up under "Authentication and Authorization" as the original django.contrib.auth model? 回答1: class User(AbstractUser): class Meta: app_label = 'auth' This can solve your problem but may cause some errors when you migrate your app. The other

Register custom user model with admin auth

一曲冷凌霜 提交于 2021-01-21 06:21:21
问题 In a Django project, I have a custom user model that adds one extra field: class User(AbstractUser): company = models.ForeignKey(Company, null=True, blank=True) This model is defined in my app, say MyApp.models . How can I get the new User model to show up under "Authentication and Authorization" as the original django.contrib.auth model? 回答1: class User(AbstractUser): class Meta: app_label = 'auth' This can solve your problem but may cause some errors when you migrate your app. The other

Can't login with normal user account in django

断了今生、忘了曾经 提交于 2021-01-07 02:43:14
问题 I'm working on an app where I have a personalized User model. I can use the superuser to login, but when I try with a normal user I get an error of wrong password and user name. When I look at the data of the user, I find that the password of normal users isn't hashed. The models definition models.py : from django.db import models from django.contrib.gis.db import models from phonenumber_field.modelfields import PhoneNumberField from django.contrib.gis.db import models as gis_models from