Problem with url template tag and namespaces

21 views
Skip to first unread message

donarb

unread,
Apr 7, 2015, 12:19:17 PM4/7/15
to django...@googlegroups.com
I'm having a problem with a generated url using the url template tag, currently using Django 1.6.5.

The appname is 'dashboard', here is the main urls.py:

urlpatterns = patterns("",
   
(r'^dashboard/', include('dashboard.urls', namespace='dashboard')),
)



Here is the dashboard urls.py:

# dashboard/urls.py
urlpatterns
= patterns("",
   
(r'^players/', include('players.urls', namespace='players')),
)


Here is the players urls.py:

# dashboard/players/urls.py
urlpatterns
= patterns("",
    url
(r'^search/?', views.PlayerSearchView.as_view(), name='search'),
)



When I code this in the template:

{% url "dashboard:players:search" %}



I get this url:

/dashboard/playerssearch


Any idea why there is no path separator between 'players' and 'search'?

donarb

unread,
Apr 7, 2015, 6:51:24 PM4/7/15
to django...@googlegroups.com
Just to follow up, I found the problem. The search url pattern had an optional trailing '/', so it was not creating the url correctly. Once I removed the optional from the regex, it worked. 
Reply all
Reply to author
Forward
0 new messages