Question

I have problem with my app1 application :

Reverse for 'app1.views.add_content' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['/add-content/(\\d+)/$']

views

@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))

urls

url(r'^/add-content/(\d+)/$', 'app1.views.add_content', name='add_content'),

in template i have error in this line

<a id="add_content" class="button" href="{% url 'app1.views.add_content' pk %}">Add New Content</a>

What is the problem?

Was it helpful?

Solution

Oh i missread Add content as add category,

your mistake is here:

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

it should be this:

{% url 'app1.views.add_content' category.pk %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top