我的app1应用程序有问题:
Reverse for 'app1.views.add_content' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['/add-content/(\\d+)/$']
视图
@login_required
def add_content(request, category_id):
form = ContentForm()
category = get_object_or_404(Category, pk=category_id)
if request.method == 'POST':
form = ContentForm(request.POST)
if form.is_valid():
content = Content()
content content_code = form.cleaned_data['content_code']
content.product_versions = form.cleaned_data['product_versions']
content.category = category
content.creator = request.user
content.save()
return HttpResponseRedirect(reverse('category-detail', args=(category.id, )))
return render_to_response('add_content.html', {
'form': form,
'category': category,
}, context_instance=RequestContext(request))
网址
url(r'^/add-content/(\d+)/$', 'app1.views.add_content', name='add_content'),
模板中的我在这行中有错误
<a id="add_content" class="button" href="{% url 'app1.views.add_content' pk %}">Add New Content</a>
有什么问题?
答案 0 :(得分:0)
哦,我想念添加内容为添加类别,
你的错误就在这里:
{% url 'app1.views.add_content' pk %}
它应该是这样的:
{% url 'app1.views.add_content' category.pk %}