我有問題,我APP1應用:的Django 1.6 URL標記錯誤
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>
問題是什麼?
看起來像'pk'未在規定的模板。我沒有看到你在'render_to_response'中將'pk'傳遞給模板。也許你的意思是'category.pk'或類似的東西? – Evert