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)
您能顯示您的書籤模型嗎? – karthikr
當然!謝謝你的方式。 我的書籤模型: – Tchec
請編輯問題 – karthikr