2013-07-12 45 views
0

在我的用戶頁面中,當我點擊我已添加書籤的鏈接時,它不會重定向到其各自的URL。請指導我。謝謝。不重定向到書籤的url鏈接

我views.py:

def user_page(request, username): 
    try: 
     user = User.objects.get(username=username) 
    except: 
     raise Http404('Reqested user not found.') 

    bookmarks = user.bookmark_set.all() 

    variables = RequestContext(request, { 
     'username':username, 
     'bookmarks':bookmarks 
     }) 
    return render_to_response('user_page.html',variables) 

我user_page.html:

{% extends "base.html" %} 
{% block title %} {{username}} {% endblock %} 
{% block head %} Bookmarks for {{username}} {% endblock %} 
{% block content %} 
    {% if bookmarks %} 
     <ul> 
      {% for bookmark in bookmarks %} 
       <li><a href="{{bookmark.url.link}}">{{bookmark.title}}</a></li> 
      {% endfor %} 
     </ul> 
    {% else %} 
     <p>No bookmarks found.</p> 
    {% endif %} 
{% endblock %} 

class Bookmark(models.Model): 
    title = models.CharField(max_length = 200) 
    user = models.ForeignKey(User) 
    link = models.ForeignKey(Link) 

    def __unicode__(self): 
     return '%s, %s' % (self.user.username, self.link.url) 
+0

您能顯示您的書籤模型嗎? – karthikr

+0

當然!謝謝你的方式。 我的書籤模型: – Tchec

+1

請編輯問題 – karthikr

回答

0

應該

{{bookmark.link.url}} 

對抗

{{bookmark.url.link}} 

由於bookmark上的FK字段是link而不是url