2014-02-17 39 views
0

我有問題,我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> 

問題是什麼?

+0

看起來像'pk'未在規定的模板。我沒有看到你在'render_to_response'中將'pk'傳遞給模板。也許你的意思是'category.pk'或類似的東西? – Evert

回答

0

哦,我missread添加內容添加類別,

你的錯誤是在這裏:

{% url 'app1.views.add_content' pk %} 

它應該是這樣的:

{% url 'app1.views.add_content' category.pk %} 
+0

我嘗試添加:category.pk,category.id,category_id,但有相同的錯誤 – quest

+0

在你的網址你應該有:'url(r'^/add-content /(?P \ d +)/ $' ,'app1.views.add_content',name ='add_content'),' –

+0

在網址中添加您的解決方案並在模板中使用以上所有內容,但具有相同的錯誤(( – quest