"NoReverseMatch at /" in Django, when I try to put a link on the [closed]

1
When I try to put a link on a button, a page with NoReverseMatch at/ error appears, I do not know what to do, I want to put this link to go to app of user registry that is called login .

<button href="{% url "login.views.registrar" %}" class="btn btn-danger">Cadastre-se</button>
  

Exception Type: NoReverseMatch   Exception Value:

     

Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0> pattern (s) tried: []

    
asked by anonymous 10.08.2015 / 02:12

1 answer

1

A NoReverseMatch error is a consequence of Django not being able to find a URL in its mapping system that resolves to a particular view, either in the template ( url tag) or in the Python code ( reverse ). In your case, the error is given when trying to form a URL for login.views.registrar , so you need to see if there is any pattern in the urls.py that maps to that view .

In your complete example (in original revision of the question) I see that there is nothing in the urls.py main (the project) that routes to any view of login :

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('article.urls'))
]

As you already have a urls.py in the app login , with a mapping for the view :

urlpatterns = [
    url(r'^registrar/new/$', views.registrar, name='registrar'),
]

So all you have to do is add a route to the login app, just like you did for article . The type of URL you choose, but as an example, assuming your site is in http://example.com/django/ and you set your urlpatterns like this:

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('article.urls'))
    url(r'login/', include('login.urls'))
]

Then the {% url "login.views.registrar" %} tag will be replaced by:

http://example.com/django/login/registrar/new/

And this URL will serve the result of view login.views.registrar . Feel free to choose another routing, if you wish, the important thing is that some routing for the view exists to avoid NoReverseMatch .

    
10.08.2015 / 23:23