NoReverseMatch at /accounts/login/ in django () - django

strong textenter image description here
Reverse for 'auth_password_reset' not found. 'auth_password_reset' is not a valid view function or pattern name.
Please Tell me how to solve this error

The error is in the html file, You would have used auth_password_reset as a url, but django cannot find the the url hence it raises the error. More on noReverseMatch Here
Here are some possible errors:
You have not given any url the name 'auth_password_reset' hence django cannot find it.
If you're using any app_name you will have to include that as well.
For example:
urls.py
app_name = 'app_one'
urlpatterns=[
path('home/', views.auth_password_reset, name='auth_password_reset'),
]
html file:
{% url 'app_one:auth_password_reset' %}

Related

NoReverseMatch at /index

I am trying to understand why I am seeing a NoReverseMatch error when trying to use Django Contact Form.
The error occurs when I add a link using the following syntax to index.html:
<h3>Contact</h3>
If I use the following hardcoded syntax then no errors occur and the link to the contact form from index.html works as expected.
<h3>Contact</h3>
What I am trying to achieve is similar to what is shown the Django tutorial about removing hard coded urls.
The full error I see is:
NoReverseMatch at /index
Reverse for 'contact' with arguments '()' and keyword arguments '{}'
not found. 0 pattern(s) tried: []
In case of need, my abbreviated urls.py is:
urlpatterns = patterns('',
...
url(r'index$', views.index, name='index'),
...
url(r'^contact/', include('contact_form.urls')'),
)
I know I am missing something obvious!
It's because there is no url with name contact.
url(r'^contact/', include('contact_form.urls')'),
is url that will map all urls starting with contact to the contact_form.urls. Official docs don't say how to access contact view, but with basic understanding of django we can do something like this:
urlpatterns = patterns('',
...
url(r'index$', views.index, name='index'),
...
url(r'^contact/', include('contact_form.urls', namespace='contacts')),
)
and the in the template:
<h3>Contact</h3>
contact_form url name is found in the source code of the module.
when you use {% url 'contact' %} in template, the 'contact' is actually the name of route. In your url patterns there is no route with this name. You should include something like this into your contact_forms.urls.py:
url(r'$', views.index, name='contact_index')
Also, you should change "contact/" pattern to:
url(r'^contact/', include('contact_form.urls', namespace='contacts'))
and then use this when creating link in template:
{% url 'contacts:contact_index' %}

Template URL redirection generating ImportError "no module named" error in Django 1.6

I'm trying to migrate my application from Django 1.0 to 1.6 and am running into a problem rendering templates with URL redirections.
My application structure is:
mysite
settings.py
urls.py
myapp
urls.py
views.py
etc.
myapp.urls contains:
from mysite.myapp import views
urlpatterns = patterns('',
# Login/Logout/Registration
url(r'^login/$', views.login, name="login"),
url(r'^registration/$', views.registration, name="registration"),
)
When I browse to /login, the URL is mapped correctly and invokes the view. However, when the view attempts to render its template, it generates this error:
ImportError at /login
No module named myapp
and points to this redirection syntax in the template:
<a href="{% url 'registration' %}">
I can browse to /registration without errors, so it has something to do with resolving back to the URL.
It must be something simple, but I'm stumped. Any suggestions would be greatly appreciated.
Finally tracked down the problem. What I had coded was correct. However, there were some other url patterns at the bottom of my url.py file that I had not converted to 1.6. For example
url(r'/schedule/$', 'schedule_list'),
And when the URL resolver looked for a reverse match, it apparently looped through the url patterns starting at the bottom and errored immediately. I guess I assumed it would either start at the top of the url patterns or there was some sort of lookup table that mapped names back to urls.
Project layout was changed in django 1.4.
Delete mysite part of the module name in myapp/urls.py. It should be:
from myapp import views

Exception Value: Caught NoReverseMatch while rendering: Reverse for 'begin' with arguments '(u'google-oauth2',)'

I make google authorization (Oauth 2.0) with django-social-auth and getting error
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
Caught NoReverseMatch while rendering: Reverse for 'begin' with arguments '(u'google-oauth2',)' and keyword arguments '{}' not found.
Exception Location: /usr/local/lib/python2.6/site-packages/django/template/defaulttags.py in render, line 450
Python Executable: /usr/local/bin/python
Python Version: 2.6.6
Template
<a rel="nofollow" href="{% url begin "google-oauth2" %}" ><img src="{{ MEDIA_URL }}social/google.png" id="google"></a>
url.py
urlpatterns = patterns('',
url(r'', include('social_auth.urls')),
)
social_auth.urls
urlpatterns = patterns('',
url(r'^login/(?P<backend>[^/]+)/$', auth, name='begin'),
url(r'^complete/(?P<backend>[^/]+)/$', complete, name='complete'),
url(r'^associate/(?P<backend>[^/]+)/$', associate, name='associate_begin'),
url(r'^associate/complete/(?P<backend>[^/]+)/$', associate_complete,
name='associate_complete'),
url(r'^disconnect/(?P<backend>[^/]+)/$', disconnect, name='disconnect'),
)
What am I doing wrong?
Please help to find the solution.
You are on django 1.3. Have you included the new url template tag with {% load url from future %}. If you have then your syntax for the url tag is incorrect and would need to be {% url 'begin' 'google-oauth2' %}. If you haven't then your syntax is correct.
Have you ensured that your social_auth.urls is being included correctly? To do this (with debug enabled) manually go to http://yourdevserver/login/google-oauth2/ and ensure you don't see a 404 page. If you do you will be able to see what url's where attempted and that should give you direction on how to fix it.

NoReverseMatch Error

I keep getting this error for the django login system. Here is part of my urls.py:
(r'^contractManagement/login', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
The exact error I am getting:
Exception Type: NoReverseMatch
Exception Value: Reverse for ''django.contrib.auth.views.login'' with arguments '()' and keyword arguments '{}' not found.
I can't understand why i am getting this error. If you need anything else let me know.
You don't show where you are trying to reverse this URL, but it looks like you have double-quoted it. If you're using the url tag, note that you don't need quotes around the url name:
{% url django.contrib.auth.views.login %}
not
{% url 'django.contrib.auth.views.login' %}
You see that ''the.unknown.view'' is reported including too many qoutes.
It is because the quoted syntax will be valid in Django 1.5 and higher. For Django 1.3 or 1.4, you should activate the future behavior by this line in the template:
{% load url from future %}
which is valid also for Django 1.5.
Example for Django 1.5+
{% url "path.to.some.view" %}
Classic syntax for Django <= 1.4.x (without "future" command) is:
{% url path.to.some.view %}
I would give your url a name (in order to do that, you need to use the url method) Also you should add a trailing slash to all your urls, cause the django CommonMiddleware is going to be doing a 302 redirect on all your urls if you don't:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(r'^contractManagement/login/', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='contract_login'),
)
Then you can use reverse in your code, or url in your templates, and if you ever decide to change the actual url (ie: changedCotractManagement/login/), as long as the name is the same, your code will still be good.
in code:
from django.core.urlresolvers import reverse
reverse('contract_login')
in template:
{% url contract_login %}
Edit: per MrOodles

Django Caught NoReverseMatch - TemplateSyntaxError

I got this error, but can't seem to figure it out. I copied it directly from a previous Django project, hence part of the confusion.
TemplateSyntaxError at Caught NoReverseMatch while rendering: Reverse for 'about' with arguments '()' and keyword arguments '{}' not found.
In my index.html, I have a link to {% url about %} didn't link to the about.html template
Urls.py has this:
urlpatterns = patterns('django.views.generic.simple',
url(r'^about/$', 'direct_to_template', {"template":"about.html"}, name="about"),
)
The problem was my second urlpattern was overriding the first pattern.
Instead of:
urlpatterns = patterns('',
it needed to be:
urlpatterns += patterns('',
The url regex is expecting an ending slash. Does the offending url end with a slash?
If you do have a PREPEND_SLASHES settings differing from your last projects, that might explain the error you're seeing!
Your url is ok. You need to check two things:
Is the urls.py included from the main urls.py?
Is the application added to INSTALLED_APPLICATIONS in settings.py?