在我的用户页面中,当我点击已添加书签的链接时,它不会重定向到其各自的网址。请指导我。谢谢。
我的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 :(得分:0)
应该是
{{bookmark.link.url}}
反对
{{bookmark.url.link}}
由于bookmark
上的FK字段为link
而非url