tags:

views:

186

answers:

2

I'm getting the following error message:

Reverse for 'code_front' with arguments '()' and keyword arguments '{'category_slug': u'code'}' not found.

I am new at this, please help.

+1  A: 

Some basics:

  1. Make sure you're passing the right arguments for the view function that the url resolves to.
  2. Make sure your that the reverse function only gets a single match, if not, give your url a unique name to reverse it with.
  3. If you're using get_absolute_url/permalink then make sure you've passed the right parameters.
  4. Make sure code_front exists as a valid item for a reverse lookup.
Gabriel Hurley
+2  A: 

The error you're getting is because there's no match in your urls.py for the view and parameters you're using.

An example:

If your urls.py look like this:

urlpatterns = patterns('',
    url(r'^YOUR_PATTERN/(?P<PARAMETER>.*)', your_view, name='code_front'),
)

You can reverse it's url like this:

In a template:

  • Using a value directly:

    {% url code_front 'some_value' %}

  • You can use variables as parameter values:

    {% url code_front variable %}

  • Using multiple parameters (if you're view needs them):

    {% url code_front variable, another_variable %}

  • Or using named parameters:

    {% url code_front parameter=variable %}

The same can be done in your python code:

  • reverse('code\_front', args=['some_value'])
  • reverse('code\_front', args=[variable])
  • reverse('code\_front', args=[variable, another_variable])
  • reverse('code\_front', kwargs={'parameter': variable})

You'll need to import the reverse function:

from django.core.urlresolvers import reverse

Guillem Gelabert