Django allauth fails when using a custom user model with the email as the primary key, I learnt about this when I tried to test the password change functionality.
Reverse for 'account_reset_password_from_key' with keyword arguments '{'uidb36': 'mgodhrawala402#gmail.com', 'key': 'bbz25w-9c6941d5cb69a49883f15bc8e076f504'}' not found. 1 pattern(s) tried: ['accounts/password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$']
I don't mind going into the code to fix this issue, since my application is still under development, I can still change authentication incase anyone has any suggestions.
The easiest fix for this problem would be adding a sequence integer pk and just updating your email field to index unique because as you see the regex path doesn't accept email format for uidb36, it only accepts 0-9A-Za-z.
If you must use email as pk you can add another path to your urls to accept your email pattern:
from allauth.account import views
path('accounts/', include('allauth.urls')),
re_path(
r"^accounts/password/reset/key/(?P<uidb36>.+)-(?P<key>.+)/$",
views.password_reset_from_key,
name="account_reset_password_from_key_accept_email",
),
Related
Ive got a users profile page and an update_profile page.
My projects urls.py:
re_path(r'^profile/(?P<username>[\w-]+)/$', include('users.urls')),
My users.urls:
path('', views.profile, name='profile'),
path('update_profile', views.update_profile, name='update_profile'),
Prior to adding the username argument to the url both of these links were working. Since adding the username argument, I can access the profile page but the update_profile page throws a 404 error. My understanding is that if the address bar reads www.site/profile/testuser/update_profile the projects urls.py will strip the www.site/profile/testuser/ and pass just update_profile to the profile apps urls.py, which then should match the path ive given.
Why isnt this working?
On my profile page I have a check that ensures the username passed in matches the logged in user (so users can only access their own profiles). I will need a similar check on the update_profile page, but currently arent passing username to the update profile page. How could I perform this check without passing it in a second time like /profile/testuser/update_profile/testuser?
Thank you.
These are the answers to your questions:
1. Your url is not working because of there is a $ at the end of users.urls url. $ is a zero width token which means an end in regex. So remove it.
2. You do not need to add <username> at the profile_update url. If you are using UpdateView, then add slug_url_kwarg attribute to UpdateView, like:
class MyUpdateView(UpdateView):
slug_url_kwarg = "username"
If you are using function based view, then simply use:
def myview(request,username):
....
I am trying to redirect django index url to admin url which I can do something like below:
# url.py
path("", admin.site.urls,),
url("^admin/", admin.site.urls, name="admin"),
However, this generating warning
WARNINGS:
?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace
Hence, I decided to create a index view and use django.view.genertic.redirectview to pass to Django admin root URL as url attribute. I am trying find better way to generate Django admin root url using reverse function.
Ahh, found it. might help to someone.
reverse('admin:index', current_app=self.name)
Django==1.11.2
django-registration-redux==1.6
When I'm trying to reset password (http://localhost:8000/accounts/password/reset/), I occur at a page with headline Django administration, and breadcrumbs below: Home › Password reset. So, this is a part of Django functionality. This may be important, though, I don't know how. But anyway, this is not the functionality of django-registration-redux.
I input an email. And get this:
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
In django-registration-redux another name is used. Namely auth_password_reset_confirm.
Well, could you give me a kick here? My settings are below:
settings.py
INCLUDE_REGISTER_URL = True
INCLUDE_AUTH_URLS = True
urls.py
urlpatterns = [
url(r'^accounts/', include('registration.backends.default.urls')),
}
As mentioned in the bug report, registration must be earlier in order then admin. Not entirely sure why and apparently it's hard to fix, as this package is maintained by several Django core team members :).
From the docs, https://django-registration.readthedocs.io/en/2.2/quickstart.html#quickstart: django.contrib.auth must be in INSTALLED_APPS, I suggest adding before registration so that the package can override the core
I have a URL like this:
url(r'^(?P<user_id>\d+)/profile/$', views.ProfileView.as_view(), name='profile'),
When the user clicks on Update Profile I do the update of form and redirect to the same Profile URL with message using messaging framework.
# views
# Use the message framework to pass the message profile successfully updated
messages.success(request, 'Profile details updated.')
# Redirect to the same view with the profile updated successfully message
return HttpResponseRedirect(reverse('profile', args=(request.user.id,)))
But I get this error:
NoReverseMatch at /5/profile/
Reverse for 'profile' with arguments '(5L,)' and keyword arguments '{}' not found.
What's wrong?
You're getting that because of how Python 2.x.x works.
All integers that comes from a database row will get suffixed with L or l (t commonly the capital L).
One way that'll work quick and dirty is
return HttpResponseRedirect(reverse('profile', args=(int(long(request.user.id)),)))
I am trying to add a user reg system to my Django site. Obviously, I want to use the built-in auth views and forms. I am going about implementing the auth password reset process. It works fine up to sending the email, but then does not redirect properly. The end result is the password reset done email being sent over and over and over. I am overriding the templates, but nothing else, right now all they have is:
{{form.As_p}}
I have changed my urls.py to use the auth.views as such:
from django.contrib.auth import views as auth_views
(r'^account/forgot/$',
auth_views.password_reset,
{'template_name': 'registration/password_reset.html',
'post_reset_redirect':'/account/password-reset-done'}
),
(r'^account/password-reset-done/$',
auth_views.password_reset_done,
{'template_name': 'registration/password_reset_done.html'}
),
It looks to me as though you need a trailing slash on the post_reset_redirect url. Have you tried that? At the moment, /account/password-reset-done won't match r'^account/password-reset-done/$' because the / in that is compulsory.
See example request 4 in the Django url dispatcher documentation: https://docs.djangoproject.com/en/dev/topics/http/urls/#example