Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't reverse match url in Admin Changeform

I read lot's of docs, tried everything and still can't understand why my template returns Reverse for '' with arguments '(1,)' and keyword arguments '{}' not found error. Please see error dump here: http://dpaste.com/721187/

The tag I use in change_form.html template is {% url pdfview 1 %}

The class FVatAdmin(admin.ModelAdmin) has get_urls method which looks like this:

def get_urls(self):
    urls = super(FVatAdmin, self).get_urls()
    my_urls = patterns('',
       url(r'^view/(?P<id>\d+)', self.admin_site.admin_view(self.pdf_view), name="pdfview"),
       url(r'^js/calculate', self.admin_site.admin_view(self.calculate), name="calc"),
        )
    return my_urls + urls

The url and pdfview defined above work just fine, but somewhat don't resolve via {% url pdfview 1 %} in a template and via reverse('pdfview', args={1}) in a view or via shell.

I just can't understand what I'm doing wrong. I'm a newbie in Django... H E L P :)

like image 202
Timus83 Avatar asked Mar 25 '12 17:03

Timus83


2 Answers

Django admin urls are namespaced in order not to clash with other urls.

Try doing the following {% url admin:pdfview 1 %}

See this for details:

https://docs.djangoproject.com/en/1.4/topics/http/urls/#topics-http-reversing-url-namespaces

like image 37
vkryachko Avatar answered Oct 26 '22 16:10

vkryachko


Put url name in quotes.

{% url "admin:pdfview" 1 %}

UPDATE: this applies only for Django 1.3/1.4 if:

 {% load url from future %}

is used.

like image 115
bmihelac Avatar answered Oct 26 '22 17:10

bmihelac