我正在研究一个简单的应用程序,在这个应用程序中,宠物用户可以为他们的宠物创建电路板并在电路板上显示图片。Django NoReverseMatch at/display/
我正试图创建一个功能,用户可以点击他们的板子,将他们重定向到他们的板上,这将显示他们所有的宠物图片。
我得到一个错误,当我尝试配置我的模板的用户重定向到其董事会。
Reverse for 'Boat' with arguments '('',)' and keyword arguments '{}' not found.
Django Version: 1.4.3
Exception Type: NoReverseMatch
Exception Value: Reverse for 'Boat' with arguments '('',)' and keyword arguments '{}' not found.
Error during template rendering
In template C:\o\mysite\pet\templates\edit.html, error at line 14
13 {% for b in board %}
14 <li><a href ="{% url world:Boat animal.id %}">{{ b.name }}</li>
我觉得问题就在这里 当在船上的用户点击。我的URLconf将捕获animal.id并把它传递到我的船的功能,但我不知道哪里出了问题
<li><a href ="{% url world:Boat animal.id %}">{{ b.name }}</li>
我edit.html
<h4>My Boards</h4>
{% if board %}
<ul>
{% for b in board %}
<li><a href ="{% url world:Boat animal.id %}">{{ b.name }}</li>
{% endfor %}
</ul>
{% endif %}
我的主URL配置
urlpatterns = patterns('',
url(
r'^admin/',
include(admin.site.urls)
),
url(
r'^',
include('pet.urls',
namespace = 'world')
),
我的宠物应用的部分URLconf个
url(
r'^(?P<animal_id>\d+)/$',
'pet.views.Boat',
name = 'Boat',
),
我的我的views.py的部分
def Profile(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('world:LoginRequest'))
if request.method == 'POST':
form = PersonForm(request.POST, request.FILES)
if form.is_valid():
person = Person.objects.get(user=request.user)
person.image = form.cleaned_data['image']
person.name = form.cleaned_data['name']
person.save()
return render(request,'profile.html',{'form': PersonForm()})
def Boat(request ,animal_id):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('world:LoginRequest'))
picture = Picture.objects.filter(board=animal_id)
return render(request,'boat.html',{'picture':picture})
谢谢你对我的帮助:]
我更我的views.py
def Display(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,'edit.html',{'board':board ,'person':person})
的我models.py
class Person(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
image = models.FileField(upload_to="images/",blank=True,null=True)
following = models.ManyToManyField('self', related_name='followers', symmetrical=False, blank=True, null=True)
def __unicode__(self):
return self.name
class Board(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
你肯定在此行'{%URL世界:船animal.id%}','animal.id'具有价值?它似乎反向无法找到该网址的参数。 – 2013-03-10 05:30:33
此外,您在您的url conf上使用了一个命名参数,但是将调用的位置参数传递给模板上的'url'标记。 – asermax 2013-03-10 05:58:01
我可以看到您的主板型号吗? – catherine 2013-03-12 08:33:46