[Django]-Django-CMS AppHooks with conflicting urls?

0👍

Have you tried r'^/$'? I’m using r'^/?$' in some app-hook urls, but I wonder if r'^$' is failing for you because of a ‘/’?

0👍

As you’ve defined each of those URL files as individual app hooks in CMS then they’ll each get attached to a certain page in the CMS e.g.

www.mysite.com/home
www.mysite.com/contacts
www.mysite.com/services
etc

Because those URL files are attached to pages this should prevent conflict between urlpatterns. For example, I’ve got an URLs file attached to a CMS app called News which looks like this;

urlpatterns = patterns(
    '',
    url(r'^(?P<slug>[-_\w]+)/$', NewsDetailView.as_view(), name='news_detail'),
    url(r'^$', NewsListView.as_view(), name='news_list'),
)

Which is attached to a page at mysite.com/news so if I go to mysite.com/news/myslug I hit that NewsDetailView and if I go to mysite.com/news I hit NewListView.

Using this example, if you had a slug for a contact you’d go to mysite.com/contacts/contact-slug to hit that NewsDetailView.

And just a sidenote on the urlpatterns in case you’re not aware, the ^ in the regex signifies the start of a pattern to match, and the $ signifies the end. URL dispatcher docs

Leave a comment