NoReverseMatch at /

后端 未结 3 1240
迷失自我
迷失自我 2021-02-02 18:23

I am trying to make pretty meaningful urls, but I guess I\'m doing it wrong.

This works:

from django.conf.urls.defaults import patterns, url
from places.         


        
3条回答
  •  故里飘歌
    2021-02-02 18:28

    This line:

    url(r'(?P[0-9A-Za-z._%+-]+)', explore_view, name='explore')
    

    ...is defining an url that takes an argument countryorcategory in the template. You need to put an argument on your url either of the following in your template:

    {% url 'explore' argument %}
    {% url 'explore' countryorcategory=argument %}
    

    If you want to continue to use non-argument urls with the same name, you can define additional urls with the same name but with different patterns. For example:

    urlpatterns = patterns('',
        url(r'(?P[0-9A-Za-z._%+-]+)', explore_view, name='explore'),
        url(r'', explore_view, name='explore'),
    )
    

    Then {% url 'explore' %} should work both with and without an argument.

提交回复
热议问题