Python 模板语法错误
我在django模板中使用{%url%}标记时遇到问题Python 模板语法错误,python,django,django-templates,Python,Django,Django Templates,我在django模板中使用{%url%}标记时遇到问题 <a href="{% url baza.views.thread category.last_post.thread.pk %}">LINK</a> 奇怪的是,它是这样工作的: {{ category.last_post.thread.pk }} <a href="{% url baza.views.thread 8 %}">LINK</a> 返回正确的值,即“8”,在我这样使用它时也
<a href="{% url baza.views.thread category.last_post.thread.pk %}">LINK</a>
奇怪的是,它是这样工作的:
{{ category.last_post.thread.pk }}
<a href="{% url baza.views.thread 8 %}">LINK</a>
返回正确的值,即“8”,在我这样使用它时也不会抛出错误:
{{ category.last_post.thread.pk }}
<a href="{% url baza.views.thread 8 %}">LINK</a>
后模型:
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)
线程视图:
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))
类别模型有“last_post”metod,它返回该类别中发布的最后一条消息
有人能帮我解决这个烦人的问题吗
问候
另外,我正在使用Django版本:1.3.1问题是下一个表达式
类别的值。last_post.thread.pk
为None或“”。带有参数的'baza.views.thread'(',)也没有相反的含义
参数(“”,)意味着
category.last_post.thread.pk
为None或“”,但为什么它与{category.last_post.thread.pk}一起工作,并返回值8,这对我的情况是正确的?如果您将这行代码改为{category.last_post.thread.pk}。它是否返回8,当然?然后更改URL.py如下:(r“^temat/(?P\d+/$”,“thread”),甚至(r“^temat/(?P\w+/$”,“thread”),对我来说这没有意义。。。我测试了最后一件事(只是为了试着理解它):在模板中:{%url baza.views.thread%},在url中(r“^temat/$”,“thread”),在视图def thread中(request,pk=None)。这不起作用,只是对你的问题的一个测试点,我认为这是一个悬赏的时刻