我认为问题是我的 URLconf 无法捕获板的名称并将其处理到我的 views.py 中,因为我收到了这个错误
NoReverseMatch at /profile/
Reverse for 'Boat' with arguments '(u"Jimmy's Board",)' and keyword arguments '{}' not found
Error during template rendering
In template C:\o\mysite\pet\templates\profile.html, error at line 19
18 {% for b in board %}
19 <li><a href ="{% url world:Boat b.name %}">{{ b.name }}</li>
20 {% endfor %}
这是我的 profile.html
<h4>My Boards</h4>
{% if board %}
<ul>
{% for b in board %}
<li><a href ="{% url world:Boat b.name %}">{{ b.name }}</li>
{% endfor %}
</ul>
{% endif %}
我的 URLConf:
url(
r'^board/(?P<name>\w+)/$',
'pet.views.Boat',
name ='Boat'
),
)
我的观点.py
def Boat(request ,name=""):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('world:LoginRequest'))
if name:
board = Board.objects.get(name=name)
picture = Picture.objects.filter(board=board)
return render(request,'boat.html',{'picture':picture})
return render(request,'boat.html',{'picture':picture})
def Profile(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('world:LoginRequest'))
board = Board.objects.filter(user=request.user)
person = Person.objects.get(user=request.user)
return render(request,'profile.html',{'board':board ,'person':person})
如何修复我的 URLconf 以将板名处理到我的 views.py 中?
我的模型.py
class Board(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name