简体   繁体   English

django上的urls-views-template标签错误

[英]urls-views-template tags error on the django

i have three pages(views,urls,templates) one with artist list with all posts one with artist details from the main list. 我有三个页面(视图,URL,模板),其中一个包含艺术家列表,所有文章均包含一个列表,其中包含艺术家详细信息。 first and second pages work fine,but i have problem on the third page i want from the artists details to go the third page and i take more details for the director where is a foreign key on the artist. 第一和第二页工作正常,但是我在第三页上有问题,我希望从艺术家详细信息转到第三页,我为导演提供更多详细信息,其中是艺术家的外键。 but not work and dont show me error if i click on the director then go me on the top from my artist details if i written on my browser 127/...../dir/1 then go me on the third page but i cant go from the second page template tag.. 但不能正常工作,如果我单击导演,然后向我显示错误,如果我在浏览器中写127 /...../ dir / 1,则从我的艺术家详细信息转到我的顶部,然后在第三页转到我,但我不能从第二页模板标记中移出。

that my code 那我的代码

my model 我的模特

class artist(models.Model):
    director = models.ForeignKey('Director')
    ..................

class Director(models.Model):
    Name = models.CharField(max_length=100,blank=True)
    ..............................

my view 我的观点

def view_dir(request, pk):
    post = get_object_or_404(Director, pk=pk)
    return render_to_response('blog/director_details.html', {
        'post': post
    })

my urls 我的网址

url(r'^view/(?P<slug>[^\.]+)/$', views.view_post, name='view_post'), #artists details
url(r'^dir/(?P<pk>\d+)/$', views.view_dir, name='view_dir'),

template tag in the artist details 艺术家详细信息中的模板标签

<p><a href="/dir/{{ director.id }}">{{post.director}}</a></p> #artists details <p><a href="/dir/{{ director.id }}">{{post.director}}</a></p> #artists详细信息

您的模板标签应为:

<p><a href="{% url 'view_dir' post.director.id %}">{{post.director}}</a></p>

如果我使用模板标签<p><a href='{% url 'view_dir' post.director.id %}'>{{post.director}}</a></p>则可以解决问题,它们被post.director.id使用post front director.id,因为里面的标签详细信息(如果不在里面),然后不使用post thnx您@Bogdan Goie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM