Luis Liz
Luis Liz

Reputation: 1959

Django-like no reverse for url

I am using this plugin

There was an error with the url so I changed it from

<a class="liker" href="{% url like content_type content_obj.id 1 %}" rel="nofollow">I Like</a>`

to

<a class="liker" href="{% url 'like' content_type content_obj.id 1 %}" rel="nofollow">I Like</a>

as recommended in this fix but I am still getting this error

Reverse for 'like' with arguments '(u'snippets-snippets', None, 1)' and keyword arguments '{}' not found.

EDIT: This is the urls.py from the app

urlpatterns = patterns(
    'likes.views',
    url(r'^like/(?P<content_type>[\w-]+)/(?P<id>\d+)/(?P<vote>-?\d+)$', 'like',
        name='like'),
)

My urls.py simply includes it

urlpatterns = patterns('snippets.views',
    (r'^likes/', include('likes.urls')),
)

Upvotes: 0

Views: 92

Answers (1)

karthikr
karthikr

Reputation: 99660

Looking at your error, it seems like your content_obj.id is evaluating to None. You might want to see if that object indeed exists. If not, you might have to do a sanity check. Something like

{% if content_obj.id %}
    <a class="liker" href="{% url 'like' content_type content_obj.id 1 %}" rel="nofollow">I Like</a>
{% endif %}

Or pass the content_obj in the context appropriately.

Upvotes: 1

Related Questions