A mistake NoReverseMatch is a consequence of Django not being able to find a URL in his mapping system that solves for a given view, either in the template (tag url) or in Python code (reverse). In your case, the error is giving when trying to form a URL to login.views.registrar, then it is necessary to see if there is any pattern in the urls.py But for this one view.
In his complete example (in original review question) I see that there is nothing in the urls.py main (project) route to any view of login:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('article.urls'))
]
How do you already own one urls.pyin the app login, with a mapping to the view desired:
urlpatterns = [
url(r'^registrar/new/$', views.registrar, name='registrar'),
]
So all you need to do is add a route to the app login, as you did to article. The URL type is yours to choose, but by way of example, assuming your site is on http://example.com/django/ and you configure your urlpatterns that way:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('article.urls'))
url(r'login/', include('login.urls'))
]
Then the tag {% url "login.views.registrar" %} 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 route if you wish, the important thing is that some routing to the view exists in order to avoid the NoReverseMatch.
Try removing quotes from tags
url. Ex.:{% url article.views.post_new %}instead of{% url "article.views.post_new" %}. Behold that question on Soen for more details (if this is the problem, comment on whether it worked, and I put it as an answer, I think it depends on the version). By the way, when you ask a question please include the relevant code snippets, not just an external link. In the case of an error involving exceptions, a stack trace usually helps too. Feel free to [Edit] your question if you want/can.– mgibsonbr
It didn’t work by taking out the quotes. Thanks for the hint of formatting, I think it’s like this now right? : D
– Allan Carlos
I noticed that in the your
urls.pythere is no standard referencinglogin.views.registrar, nor an inclusion oflogin/urls.py(as you did with thearticle-url(r'', include('article.urls'))). If no Roteia URL for that view, so there’s no way to link to it. Try including it in yoururls.py[main] something likeurl(r'login/', include('login.urls'))(only one example).– mgibsonbr
Worked perfectly @mgibsonbr. ;
<a href="{% url "login.views.registrar" %}" class="btn btn-danger">Cadastre-se</a>In the main urlsurl(r'login/', include('login.urls'))With some modifications on the outside, such as the template link in views.return render(request, "login/registrar.html", {"form": UserCreationForm() })– Allan Carlos