Reverse for 'code_front' with arguments' () 'and key arguments' {' category_slug ': u'code'} 'not found
The error you are getting is that there is no match in your urls.py for the view and parameters you are using.
Example:
If your urls.py looks like:
urlpatterns = patterns('',
url(r'^YOUR_PATTERN/(?P<PARAMETER>.*)', your_view, name='code_front'),
)
You can change its url like this:
In the template:
-
Using the value directly:
{% url code_front 'some_value' %}
-
You can use variables as parameter values:
{% url code_front variable %}
-
Using multiple parameters (if you are looking at 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 will need to import the function reverse
:
from django.core.urlresolvers import reverse
source to share
Some basics:
- Make sure you are passing the correct arguments to the view function that the URL resolves.
- Make sure the inverse function only gets one match, if not, give your url a unique name to reverse it.
- If you are using
get_absolute_url
/permalink
, make sure you pass the correct parameters. - Make sure it
code_front
exists as a valid element for reverse lookups.
source to share