url(r'^topics/(?P<topic_id>\d+)/$', views.topic, name='topic')
错误反馈是
Reverse for 'topic' with arguments '('',)' not found. 1 pattern(s) tried: ['topics/(?P<topic_id>\\d+)/$']
为何我的‘\'变成'\\',而我输入'\\'时变成了'\\\\'...
因为你字符串前面加了r,python会替你转义字符
不是很懂怎么改
改成
url('^topics/(?P<topic_id>\d+)/$', views.topic, name='topic'),了
还是一样的错误
@skrrr: 你是哪里用了reverse吗?你应该传参数kwargs,而不是args
@Uteki: 我都改成这样return HttpResponseRedirect(reverse('notes:topic', kwargs=[topic_id]))了还是不行
我试了一下把的"d+"改成了"d*"却可以了,不知道为什么
url(r'^topics/(?P<topic_id>\d*)/$', views.topic, name='topic'),
但是又有其他的错误
ValueError at /topics//
invalid literal for int() with base 10: ''
我不知道错误在哪我看traceback好像是这里
topic = Topic.objects.get(id=topic_id)
@skrrr: kwargs的值是字典不是列表
@Uteki: 前面一个已解决appreciate it
但是另一个又出错了....
urls.py:
#用户编辑条目
url(r'^edit_entry/(?P<entry_id>\d+)/$', views.edit_entry, name= 'edit_entry'),
views.py:
def edit_entry(request, entry_id):
"""编辑既有条目"""
entry = Entry.objects.get(id=entry_id)
topic = entry.topic
if request.method != 'POST':
#填充当前信息
form = EntryForm(instance=entry)
else:
form = EntryForm(instance=entry, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('my_notes:topic', kwargs={'topic.id': topic.id, 'entry.id': entry.id}))
错误是
NoReverseMatch at /edit_entry/1/
Reverse for 'edit_entry' with arguments '('',)' not found. 1 pattern(s) tried: ['edit_entry/(?P<entry_id>\\d+)/$']