0

I made this many times and it worked, but not this time.

I get this error when I try to use {% url path.to.view %} django's template tage:

AttributeError at /login/ 'str' object has no attribute 'regex'


urls.py (main)

urlpatterns= patterns('', (r'', include('authenticate.urls')),  )

urls.py (my app)

urlpatterns= patterns('authenticate.views', url(r'^login/$','login'),)

login.html

{{ form }}
{% url authenticate.views.login %} < --- Error comes here

in the views:

return render_to_response('login.html',{'form':form},context_instance=RequestContext(request),  )

Doesn't also work with:

 {% url authenticate.views.login %}
 {% url 'authenticate.views.login' %}
 {% url "authenticate.views.login" %}

This is on django 1.4; what possibly I'm doing wrong, or what do I miss in that version of django?

Thanks in Advance!


Update:

I can also add that using reverse in my views doesn't work and gives me the same error above:

from django.core.urlresolvers import reverse

result = reverse('django.contrib.auth.views.password_reset')         
HttpResponse(result)

Error:

AttributeError at /abc/ 'str' object has no attribute 'regex'

silviomoreto
  • 5,629
  • 3
  • 30
  • 41
securecurve
  • 5,589
  • 5
  • 45
  • 80

2 Answers2

0

Check this https://docs.djangoproject.com/en/1.4/topics/http/urls/

You can add a name to your URL to help the refer. Also check how you are declaring the pattern. It should be done like this:

urlpatterns = patterns('',
    url(r'^archive/(\d{4})/$', archive, name="full-archive"),
    url(r'^archive-summary/(\d{4})/$', archive, {'summary': True}, "arch-summary"),
) 
silviomoreto
  • 5,629
  • 3
  • 30
  • 41
  • I tried giving a name to my view in the url as you referred above, but it's giving the same result, I just forgot to list it in my question. The problem is not in the urls file, as when I remove the {% url view %} template tag from my template, thing go well. The problem here is in the template url tag. – securecurve Nov 20 '12 at 16:23
0

I got it :))

The problem wasn't in the url template tag, it was in another urls file that's been included in the main one; the problem doesn't show till my app. hits url template tage or django's reverse method, otherwise, django doesn't complain about any url!!

securecurve
  • 5,589
  • 5
  • 45
  • 80