Django-CMS AppHooks with conflicting URLs?

I am trying to use django-cms app hooks in a different way. I only have an application with different website pages. For each page I created an AppHook, since I want to control all of them with cms.

To do this, inside the application I made a package with the urls.py file for each page, for example:

/urls /home_urls.py /portfolio_urls.py /contacts_urls.py 

Here is the definition of some application hooks:

 class WebsiteHome(CMSApp): name = _("cms-home") urls = ["website.urls.home_urls"] apphook_pool.register(WebsiteHome) class WebsiteServices(CMSApp): name = _("cms-services") urls = ["website.urls.services_urls"] apphook_pool.register(WebsiteServices) 

In any case, the problem is this: I have no control over regular expressions. Each of them introduces the first regular expression that it has discovered, in this case urlpattern in

website.urls.home_urls

Despite the fact that they have different apphHooks.

Example:

if I write slug contacts (which have apphook to WebsiteContacts), it still goes to the home_urls.py file associated with the SiteHome (application hook).

Has anyone had a similar problem?


Basically, I'm trying to say that this is something wrong with regex. I can not do:

 url(r'^$', [...]), 

only

 url(r'^', [...]), 

If I put '$', it will not go into any regular expression. If I take it, it will always be on

website.urls.home_urls.py

Despite the bullets having different Apphooks associated with different urls.py files.

+4
source share
2 answers

Have you tried r'^/$' ? I use r'^/?$' In some application urls, but I wonder if r'^$' fails for you due to '/'?

0
source

As you defined each of these URL files as separate application hooks in the CMS, then each of them will be bound to a specific page in the CMS, for example.

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

Since these URL files are attached to pages, this should prevent a conflict between urlpatterns . For example, I have a URL file attached to a CMS application 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 tied to a page in mysite.com/news , so if I go to mysite.com/news/myslug I click on this NewsDetailView and if I go to mysite.com/news I will mysite.com/news NewListView .

Using this example, if you have a contact pool, you will go to mysite.com/contacts/contact-slug to click NewsDetailView .

And only the side link on urlpatterns, if you don’t know, ^ in the regular expression means the beginning of the pattern match, and $ means the end. URL Manager Docs

0
source

All Articles