no reverse match with django auth views

  • Last Update :
  • Techknowledgy :
<form id="login-form" method="post" action="">

Suggestion : 2

If no match can be made, reverse() raises a NoReverseMatch exception.,The reverse() function can reverse a large variety of regular expression patterns for URLs, but not every possible one. The main restriction at the moment is that the pattern cannot contain alternative choices using the vertical bar ("|") character. You can quite happily use such patterns for matching against incoming URLs and sending them off to views, but you cannot reverse such patterns.,django.urls utility functions reverse() reverse_lazy() resolve() get_script_prefix() ,It is useful for when you need to use a URL reversal before your project’s URLConf is loaded. Some common cases where this function is necessary are:

from news
import views

path('archive/', views.archive, name = 'news-archive')
# using the named URL
reverse('news-archive')

# passing a callable object
#(This is discouraged because you can 't reverse namespaced views this way.)
      from news
      import views reverse(views.archive)
from django.urls
import reverse

def myview(request):
   return HttpResponseRedirect(reverse('arch-summary', args = [1945]))
>>> reverse('admin:app_list', kwargs = {
   'app_label': 'auth'
})
'/admin/auth/'
>>> reverse('cities', args = ['Orléans'])
'.../Orl%C3%A9ans/'
# Resolve a URL
match = resolve('/some/path/')
# Print the URL pattern that matches the URL
print(match.url_name)

Suggestion : 3

Arguments '()' and keyword arguments '{}' means that the URL application is searching for have no arguments or keyword arguments in it. , Make sure you are passing the correct number of Arguments or Keyword arguments in URL template tag. , Django is trying to find a URL with name 'url_name' and it is not able to find any pattern match. , As you can see in urls.py file, URL with name 'news-year-archive ' expects an argument 'year' in it. If you are not passing the year in url template tag, application will throw the error. 

Every Django developer encounters below error at least once in their life for sure.

NoReverseMatch at / url_path / Reverse
for 'url_name'
with arguments '()'
and keyword arguments '{}'
not found.n pattern(s) tried: []

from django.urls import path

from . import views

app_name = 'polls'
urlpatterns = [
#...
path('articles/<int:year>/', views.year_archive, name='news-year-archive'),
   #...
   ]

For example in below template code snippet,

<a href="{% url 'news-year-archive' 2012 %}">2012 Archive</a>

So

<a href="{% url 'news-year-archive' %}">2012 Archive</a>

should be

<a href="{% url 'news-year-archive' 2012 %}">2012 Archive</a>

Suggestion : 4

I’m using vanilla installation and after sending simple POST from swagger to /api/v1/dj-rest-auth/password/reset/ I get this error,I believe the problem lies in /dj_rest_auth/urls.py line 10 First name should be password_reset_confirm to refer to existing template in auth/urls.py, secondly regex must include parameters this template is called with.,I have solved it by adding the file /templates/registration/password_reset_email.html with the content:,Also I believe password/reset/confirm should not be in the email as this is an API endpoint that expects POST and JSON data in the body. So will never work as a link from email.

I believe the problem lies in /dj_rest_auth/urls.py line 10 First name should be password_reset_confirm to refer to existing template in auth/urls.py, secondly regex must include parameters this template is called with.

# Is
path('password/reset/confirm/', PasswordResetConfirmView.as_view(), name='rest_password_reset_confirm'),
# Should be
path('password/reset/confirm/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name='password_reset_confirm'),

I have solved it by adding the file /templates/registration/password_reset_email.html with the content:

{
   % load i18n %
} {
   % autoescape off %
} {
   % blocktranslate %
}
You 're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktranslate %}

{
   % translate "Please go to the following page and choose a new password:" %
} {
   % block reset_link %
} {
   {
      protocol
   }
}: //{{ domain }}{% url 'rest_password_reset_confirm' %}
uid: {
   {
      uid
   }
}
token: {
   {
      token
   }
} {
   % endblock %
} {
   % translate 'Your username, in case you’ve forgotten:' %
} {
   {
      user.get_username
   }
}

{
   % translate "Thanks for using our site!" %
}

{
   % blocktranslate %
}
The {
   {
      site_name
   }
}
team {
   % endblocktranslate %
} {
   % endautoescape %
}
password / reset / confirm /
1._
password / reset / confirm /
re_path(
r"^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",
      views.password_reset_from_key,
      name="account_reset_password_from_key",
      ),