NoReverseMatch at /auth/password/reset/ - django

I am using dj-rest-auth package to do auth related functions, installed the package and added to installed apps and included it in main url as follows
path('auth/', include('dj_rest_auth.urls')),
it works for login, logout etc, but when I do password reset it throws the error
http://127.0.0.1:8000/auth/password/reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name
NoReverseMatch at /auth/password/reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Request Method: POST
Request URL: http://127.0.0.1:8000/auth/password/reset/
Django Version: 3.2
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Exception Location: /home/biju/Desktop/reporting-system/lib/python3.8/site-packages/django/urls/resolvers.py, line 694, in _reverse_with_prefix
Python Executable: /home/biju/Desktop/reporting-system/bin/python
Python Version: 3.8.10
Python Path:
['/home/biju/Desktop/reporting-system',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/biju/Desktop/reporting-system/lib/python3.8/site-packages']
Server time: Fri, 01 Apr 2022 16:01:18 +0000

the urlpattern in https://github.com/iMerica/dj-rest-auth/blob/master/dj_rest_auth/urls.py:
...
path('password/reset/confirm/', PasswordResetConfirmView.as_view(), name='rest_password_reset_confirm'),
...
so you need to change 'password_reset_confirm' to 'rest_password_reset_confirm' in your html url tag or in django function call like reverse()
update:
see https://dj-rest-auth.readthedocs.io/en/latest/faq.html
"You need to add password_reset_confirm url into your urls.py (at the top of any other included urls). Please check the urls.py module inside demo app example for more details."
the package expects something like:
path('password/reset/confirm/<uidb64>/<token>',TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
path('auth/', include('dj_rest_auth.urls')),
see the demo urls.py: https://github.com/iMerica/dj-rest-auth/blob/24678437b3cdf3fa663880ab66a42aa0992b1d39/demo/demo/urls.py
strange for me that it is mentioned only in the FAQ - looks to me like a bug in the confirm email generation where they use the wrong urlpattern name without the "rest" prefix
.

Related

Django HttpResponseRedirect and NoReverseMatch

I am trying to redirect to a new form page whose fields get automatically filled with the data sent from the view function.
My urls.py is:
url(r"user_dashboard/NewRequest/([\{.*\}])", views.request_form, name = "NewRequest")
The view function which is sending the data is present at:
url(r"user_dashboard/NReq", views.request_request, name="NReq"),
which calls the above url.
The return statement from my view function is:
return HttpResponseRedirect(reverse(request_form, kwargs={"device_type":devicetype}))
But, I get the following error:
NoReverseMatch at /user_dashboard/NReq
Reverse for 'inventory_management_app.views.request_form' with keyword arguments '{u'device_type': u'Laptop'}' not found. 1 pattern(s) tried: ['user_dashboard/NewRequest/([\\{.*\\}])']
Request Method: POST
Request URL: http://127.0.0.1:8000/user_dashboard/NReq
Django Version: 1.11.13
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'inventory_management_app.views.request_form' with keyword arguments '{u'device_type': u'Laptop'}' not found. 1 pattern(s) tried: ['user_dashboard/NewRequest/([\\{.*\\}])']
Exception Location: C:\Anaconda2\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 497
Python Executable: C:\Anaconda2\python.exe
Python Version: 2.7.14
Python Path:
['E:\\inventory management\\inventory_management_service',
'C:\\Anaconda2\\python27.zip',
'C:\\Anaconda2\\DLLs',
'C:\\Anaconda2\\lib',
'C:\\Anaconda2\\lib\\plat-win',
'C:\\Anaconda2\\lib\\lib-tk',
'C:\\Anaconda2',
'C:\\Users\\Jaimik Jain\\AppData\\Roaming\\Python\\Python27\\site-packages',
'C:\\Anaconda2\\lib\\site-packages',
'C:\\Anaconda2\\lib\\site-packages\\win32',
'C:\\Anaconda2\\lib\\site-packages\\win32\\lib',
'C:\\Anaconda2\\lib\\site-packages\\Pythonwin',
'C:\\Anaconda2\\lib\\site-packages\\pywinpty-0.5-py2.7-win-amd64.egg']
Server time: Wed, 6 Jun 2018 07:48:44 +0000
Can anyone please tell me what's wrong present in the above code?
Instead of the following regex expression url(r"user_dashboard/NewRequest/([\{.*\}])", views.request_form, name = "NewRequest") in your URL:
try with re group name:
url(r"user_dashboard/NewRequest/(?P<device_name>\w.+)", views.request_form, name = "NewRequest")
Make sure you have device_name as a default argument in your view
def request_form(request,device_name=''):
'''

Django's URL regex engine is failing

Django's URL regex engine is failing and I have no idea why. Even my sanity checks are failing horribly.
Here's my urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^a', 'placemyorder.views.home', name='home'),
)
I get this 404 error:
Page not found (404)
Request Method: GET
Request URL: http://[ip address]/a/
Using the URLconf defined in placemyorder.urls, Django tried these URL patterns, in this order:
1. ^a [name='home']
The current URL, , didn't match any of these.
when I visit
http://[ip address]/a
And it's hosted on Django 1.5.2 with Python 2.7.3 on Ubuntu 12.04 behind nginx if that info is relevant.
Here's a clue: The current URL, , didn't match any of these.
It should say: The current URL, http://[ip address]/a, didn't match any of these.
So the dispatcher isn't getting the request url.
Take a look at this solution:
Django + NGINX URL Problem

Problems with {% URL %} tag

I've been trying to implement hyper links into my Django application, where a list of items are displayed, clicking on each item will take you to a page detailing more information about the item.
I've been wrestling with the {% URL %} tag and despite searching over here, the internet and books on the matter, I've yet to get it working.
In views.py:
def Link(request):
return render_to_response('Search_Page.html')
In Urls.py:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'ParkManager.views.home', name='home'),
# url(r'^ParkManager/', include('ParkManager.foo.urls')),
url(r'^test/', Search_Page),
url(r'^search/', Search),
url(r'^details/', Details_Main),
url(r'^Link/(d+}/$', Link),
url(r'^$', 'Parks.views.Link', name="home"),
in my template:
test
Thanks for your time :)
EDIT
error:
The page loads however the link only takes you to 127 .0 .0 .1 /8000
when I add: test
I get:
NoReverseMatch at /search/
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
Request Method:
GET
Request URL:
http://127.0.0.1:8000/search/?search=a&type=parks&submit=Search
Django Version:
1.4.2
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
Exception Location:
C:\Python27\lib\site-packages\django\template\defaulttags.py in render, line 424
Python Executable:
C:\Python27\python.exe
Python Version:
2.7.3
Python Path:
['C:\\Users\\User\\Documents\\Django\\ParkManager',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
'C:\\Python27\\lib',
'C:\\Python27\\lib\\plat-win',
'C:\\Python27\\lib\\lib-tk',
'C:\\Python27',
'C:\\Python27\\lib\\site-packages']
Server time:
Mon, 4 Feb 2013 16:05:30 +0000
Error during template rendering
In template C:\Users\User\Documents\Django\ParkManager\Templates\Details_Main.html, error at line 23
Reverse for 'name' with arguments '(u'North West Thrill Centre',)' and keyword arguments '{}' not found.
A clue:
Exception Location:
C:\Python27\lib\re.py in _compile, line 242
Your issue is not related to the url tag. It is a mal-formed regex in your urls.py.
urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'ParkManager.views.home', name='home'),
# url(r'^ParkManager/', include('ParkManager.foo.urls')),
url(r'^test/', Search_Page),
url(r'^search/', Search),
url(r'^details/', Details_Main),
# LINE BELOW has an open parentheses and not a closed parentheses.
url(r'^Link/(d+}/$', Link),
#url(r'^Link/(d+)/$', Link), #line fixed
url(r'^$', 'Parks.views.Link', name="home"),
unbalanced parenthesis is problem at this line:
url(r'^Link/(d+}/$', Link),
You have forgotten to close the parenthesis.
If you are using {% url %} tag in Django < 1.5, use it this way:
{% load url from future %}
{% url 'namespace:viewname' arg1, arg2 %}
{% url 'namespace:viewname' kwarg1=val, kwarg2=val2 %}
If you are using Django 1.5, you don't have to load the special url tag. If you are not using namespaces (good if you are using general view names like list, detail etc. and you want to distinguish between apps, e.g.: author:list or book:list) use only the view name. Check the documentation, there is a good section about the url tag - https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#url

little trouble while trying to run emencia.django.newsletter

I did exactly (or so I think) as the docs describe to install emencia.django.newsletter (https://github.com/Fantomas42/emencia-django-newsletter). I installed all dependencies and emencia.django.newsletter from github. All installed successfully.
I also added this in my urls.py
urlpatterns += patterns('',
url(r'^newsletters/', include('emencia.django.newsletter.urls')),
)
I synced the database and when I give http://localhost:8000/newsletters/ (even having logged in as admin) I get a 404 error page.
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/newsletters/
[...]
^newsletters/ ^mailing/
^newsletters/ ^tracking/
^newsletters/ ^statistics/
^newsletters/ ^ ^preview/(?P<slug>[-\w]+)/$ [name='newsletter_newsletter_preview']
^newsletters/ ^ ^(?P<slug>[-\w]+)/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$ [name='newsletter_newsletter_contact']
^dowser/
^media/(?P<path>.*)$
Where did I go wrong?
Obviously there is no page at /newsletters/ as you can see in the urls.py.
Try /newsletters/mailing/

Django-grappelli admin: No reverse match error

I've been working on a django project for a while now that uses grappelli for the admin and all of a sudden today my change_form.html template is throwing the following error:
Caught NoReverseMatch while rendering: Reverse for "grp_related_lookup" with arguments '()' and keyword arguments '{}' not found.
The offending line of code is line 38:
37 $.each(related_lookup_fields_fk, function() {
38 $("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
39 });
which is preceded by this bit of code:
var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model_admin %};
Obviously it's the {% url grp_related_lookup %} bit that's causing the problem.
I don't understand how the template is resolving grp_related_lookup to grappelli.views.related.related_lookup. I have tried replacing grp_related_lookup with grappelli.views.related.related_lookup and that didn't work either. Also, in the template the offending line looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"});
but in the error message it looks like this:
$("#id_" + this).grp_related_fk({lookup_url:"{% url 'grp_related_lookup' %}"});
I don't know if the single quotes surrounding grp_related_lookup might have something to do with the problem or not. Is that how django rendered the function call? Is it passing the string 'grp_related_lookup' to the url template tag? If so, what might have caused this to break suddenly?
Some additional info:
The value of related_lookup_fields is an empty list []. I am not defining any related_lookup_fields in my admin.py.
I threw a couple debug statements into the grappelli.views.related.related_lookup view function and it doesn't appear to be getting called.
I have not touched any of the templates recently.
Hopefully someone can point me in the right direction... Thanks!
Do you still have 'grappelli.urls' included in your URLconf? That the only reason I see that would cause this error. You can try using python manage.py shell:
from django.core.urlresolvers import reverse
print reverse('grp_related_lookup')
If this line returns the correct URL, you shouldn't get a NoReverseMatch in your template.
The quotes around grp_related_lookup shouldn't be a concern. The {% url %} tag accepts both quoted and unquoted strings as first argument, so django normalizes it to quoted strings. This behaviour is going to change in the future: you'll be able to pass template variables to {% url %} using unquoted strings. {% url foo %} and {% url "foo" %} won't give the same result, see the 1.3 release notes for details about this.
I encountered the same behavior with Django 1.5 and Grappelli 2.4.4.
To fix the problem I had to add
url(r'^grappelli/', include('grappelli.urls')),
to urlpatterns.
I faced with this problem today, when I tried to delete data in admin.Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': ''}' not found.
I have put the url(r'^grappelli/', include('grappelli.urls')) in urls.py
The solution is pretty strange: just update the grappelli to the latest version. (I updated it from 2.5.6 to 2.6.3)
I faced this problem yesterday. The Django-grapelli I used was the one that was included in the FileBrowser installation. I solved the problem by upgrading Django-grapelli. Just type:
pip install --upgrade django-grappelli
I had a similar issue with urls and noticed that I need
{% load url from future %}
in the template if I want to have quoted url tags. That's also mentioned in the official django documentation: https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#url
I seem to be encountering this same issue, but when I run the suggested console test I get this:
Python 2.7.9 (default, Apr 7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> print reverse('grp_related_lookup')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 579, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/Users/tsantor/.virtualenvs/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 496, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'grp_related_lookup' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
And my urls.py looks like this:
urlpatterns = patterns(
# Admin
url(r'^grappelli/', include('grappelli.urls')),
url(r'^admin/', include(admin.site.urls), name="admin"),
# main views
#url(r'^$', RedirectView.as_view(url='/admin'), name='home'),
# API
url(r'^api/', include('api.urls', namespace='api')),
)
I also have the latest Grappelli (2.6.4) running on Django (1.8.2). By the way, it seems it only occurs when I try to access and add or edit view. The control panel and list views work.
I added
path('grappelli/', include('grappelli.urls')),
and fixed the problem.