Yet Another NoReverseMatch Error

56 views
Skip to first unread message

ne...@vidyasource.com

unread,
May 12, 2013, 4:08:12 AM5/12/13
to django...@googlegroups.com
I have an app within my project called popular_keywords. 

Within urls.py I have this:

urlpatterns = patterns("apps.popular_keywords.views",
                       url("^%keyword/(?P<keyword>.*)%s$" % _slashes, "matching_items_list", name="matching_items")
)


Within views.py I have this function:

def matching_items_list(request, keyword=None, template="popular_keywords/keyword_matched_list.html")



In my template I have this:

<a href="{% url "matching_items" keyword=keyword %}">


The problem is when I view my page I find this:


NoReverseMatch at /

Reverse for 'matching_items' with arguments '()' and keyword arguments '{u'keyword': 'Cake'}' not found.

I thought I had my bases covered, but as a Django noob, I would appreciate help on whatever silly thing I missed. Please let me know if I need to provide more information.

Thanks.





Tom Evans

unread,
May 13, 2013, 4:28:54 AM5/13/13
to django...@googlegroups.com
On Sun, May 12, 2013 at 9:08 AM, <ne...@vidyasource.com> wrote:
> I have an app within my project called popular_keywords.
>
> Within urls.py I have this:
>
> urlpatterns = patterns("apps.popular_keywords.views",
> url("^%keyword/(?P<keyword>.*)%s$" % _slashes,
> "matching_items_list", name="matching_items")
> )
>

What is the contents of _slashes?


Cheers

Tom

Neil Chaudhuri

unread,
May 13, 2013, 9:56:37 AM5/13/13
to django...@googlegroups.com
Here is slashes:

_slashes = (
"/" if settings.BLOG_SLUG else "",
"/" if settings.APPEND_SLASH else "",
)

Thanks.
> --
> You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/y_G3Zirkn7s/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Tom Evans

unread,
May 13, 2013, 10:17:06 AM5/13/13
to django...@googlegroups.com
On Sun, May 12, 2013 at 9:08 AM, <ne...@vidyasource.com> wrote:
> I have an app within my project called popular_keywords.
>
> Within urls.py I have this:
>
> urlpatterns = patterns("apps.popular_keywords.views",
> url("^%keyword/(?P<keyword>.*)%s$" % _slashes,
> "matching_items_list", name="matching_items")
> )

I hadn't had my coffee when I first saw this. This isn't a valid string format:

"^%keyword/(?P<keyword>.*)%s$"

Probably just missing a 's' from the first format specifier, eg '^%skeyword…'.

Does it work correctly if you fix the format string?

Cheers

Tom

Neil Chaudhuri

unread,
May 13, 2013, 10:19:31 AM5/13/13
to django...@googlegroups.com
Good catch. That was a typo. Let me cut and paste directly:

urlpatterns = patterns("apps.popular_keywords.views",
url("^%skeyword/(?P<keyword>.*)%s$" % _slashes, "matching_items_list", name="matching_items")
)

Perhaps I should try some of your coffee.

Thanks.

Tom Evans

unread,
May 13, 2013, 10:31:12 AM5/13/13
to django...@googlegroups.com
On Mon, May 13, 2013 at 3:19 PM, Neil Chaudhuri <ne...@vidyasource.com> wrote:
> Good catch. That was a typo. Let me cut and paste directly:
>
> urlpatterns = patterns("apps.popular_keywords.views",
> url("^%skeyword/(?P<keyword>.*)%s$" % _slashes, "matching_items_list", name="matching_items")
> )
>
> Perhaps I should try some of your coffee.
>
> Thanks.

Does that make it work or does it still fail to reverse? I'm running
out of trouble shooting ideas - double check that the urlconf is
actually being used - start at the project level urlconf, and follow
the includes down.

Cheers

Tom

Neil Chaudhuri

unread,
May 13, 2013, 10:34:44 AM5/13/13
to django...@googlegroups.com
Oh sorry I wasn't clear. The first time I typed the patterns function call out. So in other words, the %s was in there all along. I just misrepresented it in my question. Things are failing even with the correct call and have been all along.

Could you provide more details about how I can double-check the urlconf and follow the includes down?

Thanks.

Tom Evans

unread,
May 13, 2013, 10:54:53 AM5/13/13
to django...@googlegroups.com
On Mon, May 13, 2013 at 3:34 PM, Neil Chaudhuri <ne...@vidyasource.com> wrote:
> Oh sorry I wasn't clear. The first time I typed the patterns function call out. So in other words, the %s was in there all along. I just misrepresented it in my question. Things are failing even with the correct call and have been all along.
>
> Could you provide more details about how I can double-check the urlconf and follow the includes down?
>
> Thanks.
>

So, the url conf hierarchy starts with whatever is specified in
settings.ROOT_URLCONF. This urlconf includes other urlconfs, trace the
includes down from the top level and verify that this urlconf that
your url is being defined in is actually included in the project.

A simple way of doing this is ensuring that the view is available (and
runs) if you directly go to that url.

This is not necessarily meant to find anything, it is just verifying
that everything is actually set up as you think it is.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages