labuzm
labuzm

Reputation: 115

TemplateSyntaxError

I'm having problem using {% url %} tag in django template.

<a href="{% url baza.views.thread category.last_post.thread.pk %}">LINK</a>

Throwing this error:

Caught NoReverseMatch while rendering: Reverse for 'baza.views.thread' with arguments '('',)' and keyword arguments '{}' not found.

What's weird, it works used like this:

{{ category.last_post.thread.pk }}

returns correct value which is '8', also doesn't throw error when I'm using it like this:

<a href="{% url baza.views.thread 8 %}">LINK</a>

Above code works fine, and redirects to thread.

my urls.py :

...
(r"^temat/(\d+)/$", "thread"),
...

post model:

class Post(models.Model):
    title = models.CharField(max_length=60)
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(User, blank=True, null=True)
    thread = models.ForeignKey(Thread)
    body = models.CharField(max_length=10000)

thread view:

def thread(request, pk):
    posts = Post.objects.filter(thread=pk).order_by("created")
    posts = mk_paginator(request, posts, 20) # ZMIEN TAKZE W get_thread_page
    t = Thread.objects.get(pk=pk)

    return render_to_response("baza/thread.html", add_csrf(request, posts=posts, pk=pk, title=t.title,
    element_pk=t.element.pk, media_url=MEDIA_URL, path = request.path))

category model has "last_post" metod which returns last msg posted in this category.

Could someone help me with this annoying problem?

Regards.

Ps. I'm using Django Version: 1.3.1

Upvotes: 3

Views: 860

Answers (1)

Goin
Goin

Reputation: 3974

The problem is that the value of the next expression category.last_post.thread.pk is None or ''. And no Reverse for 'baza.views.thread' with arguments '('',)'.

Arguments ('',) implies that category.last_post.thread.pk is None or ''

Upvotes: 1

Related Questions