0
votes

I need some help on django 1.8

ERROR :
Exception Type : NoReverseMatch
Exception Value : Reverse for 'views.login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

urls.py

urlpatterns = [  
    url(r"^login/$", TemplateView.as_view(template_name = 'auth/login.html'))
]

login.html

<html>
   <body>
      <!-- action = "{% url 'connecte_login' %}" -->
      <form name = "form" action = "{% url 'views.login' %}" method = "POST" >
           {% csrf_token %}
         <div style = "max-width:470px;">
            <center>
              <h5> <font color="blue">KEYSTONE AUTHENTIFICATION </font> </h5>

              <b>Username :</b>  <input type = "text" style = "margin-left:7%;"
                  placeholder = "Identifiant" name = "username" />
            </center>
         </div>

      </form>
   </body>
</html>

views.py

from django.shortcuts import render,redirect
from .forms import *

 def login(request):
   return render(request, "auth/authSuccess.html", context_dic)

authSuccess.html

<html>
   <body> <b>IT WORKS !</b> </body>
</html>

I don't know why it gives me that error !

thank you.

1
There are at least 10 duplicate questions on the right in the related section. Please attempt to solve the problem yourself first. - Sayse
Possible duplicate of django reverse error NoReverseMatch - Sayse
I saw them, but it didn't help me :( - Rãã Møó
Please update your question to include what you've tried and researched then. You need to give your url a name and then use that name. - Sayse
Because thats what the documentation told you to do. - Sayse

1 Answers

0
votes

As @Sayse says in his comment, documentation told you to give your view a name to use reverse lookup. To understand how it works you need to look at django.core.urlresolvers.RegexURLResolver#_reverse_with_prefix method. Here in line 462 (Django 1.9) it executes possibilities = self.reverse_dict.getlist(lookup_view), where lookup_view is your 'views.login' argument of url template tag. So you don't have this name - it wont work.

Hovever, you can use full dotted path to your view like this:

{% url 'path.to.some_view' v1 v2 %}

Not views.view but app.views.view. But you should not do this since it is deprecated and will removed in Django 1.10. Hope it will help you.