Django Relationships- TemplateSyntaxerror

时间:2012-02-18 16:20:10

标签: django

我正在为我的项目使用coleifer / Django-Relationships包。我一直在努力工作。

我在用户个人资料模板中添加了模板'relationship_add.html',这样当用户找到另一个用户并且两者都没有互相跟随时,用户就可以轻松点击关注按钮彼此。

在用户个人资料模板中包含模板后:

{% include 'relationships/relationship_add.html' %}

我在/ profiles / picomon /

收到TemplateSyntaxError
RelationshipStatus not found
Request Method: GET
Request URL:    http://127.0.0.1:8000/profiles/picomon/
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:    
RelationshipStatus not found
Exception Location: build\bdist.win32\egg\relationships\templatetags\relationship_tags.py in render, line 32
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.2

Template error

In template c:\python27\scripts\myweb\templates\relationships\relationship_add.html, error at line 9

以下是relations / relationship_add.html

中的代码
{% load relationship_tags %}

 {% if request.user != profile.user %}

  {# decide whether or not the current user is following this user #}

  {% if_relationship request.user profile.user "following" %} 

    {# they are following them, so show a "remove" url #}
    <a href="{{ profile.user|remove_relationship_url:"following" }}">Unfollow</a>

  {% else %}

    {# they are not following them, so show a link to start following #}
    <a href="{{ profile.user|add_relationship_url:"following" }}">Follow</a>



    {% endif_relationship %} 

     {% else %}
       <p>This is you!</p>
     {% endif %}

我会做些什么调整来完成这项工作?请告诉我。

1 个答案:

答案 0 :(得分:0)

根据我的经验,TemplateSyntaxError并不总是意味着它所说的。我会通过检查shell中的核心逻辑或单元测试来检查所有自定义标记和过滤器(if_relationship,remove_relationship_url,add_relationship_url)是否正常工作。

在此之前,我只是从模板中删除位,直到它再次开始工作。它可以很容易地缩小导致问题的原因。