django-cms app hook at homepage error

本秂侑毒 提交于 2019-12-08 12:02:00

问题


I'm playing with django-cms and I want to create an app-hook to an existing application. This is fine if the page I choose to show the app-hook is not the homepage.

This is my urls.py for my application that I'm hooking in:

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

urlpatterns = patterns('films.views',
    url(r'^$', 'index'),
    url(r'^(?P<film_id>\d+)/$', 'detail'),
)

The cms_app.py is as follows:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _

class FilmApphook(CMSApp):
    name = _("Film Apphook")
    urls = ["films.urls"]

apphook_pool.register(FilmApphook)

I have the urls:

/ (<- set to have the slug home, but django-cms doesn't seem to serve it at /home if it's the startpage)
/news
/...

When I set the home page to have the app-hook, it renders the index of my films.views, buy I get a 404 going to any detail actions.

I.e

/ <- correctly renders films.index
/home <- 404
/home/1 <- 404
/1 <- 404

If I change the app-hook to be under news instead, everything works fine, (or if I make another page the home page).

/news <- correctly renders films.index
/news/1 <- correctly renders films.detail

The problem seems to be that django-cms ignores the slug for the start-page, is there anyway to work around this?

I should probably mention that I've tried to set the overwrite url to work round this, and while /home is then served, /home/1 still gives a 404.


回答1:


It's a bit of a dodgy workaround, but I can live with it for today. I basically add a child page to /home named /films, making sure it's not in navigation, and add the app-hook there as well.

The home/fake-child-page have no content of their own, so that's why I can live with it, and I'm left with the urls I want.

/ <- films.views.index
/films/1 <- films.views.details/1



回答2:


This might be a bug with your version of django-cms:

https://github.com/divio/django-cms/issues/47



来源:https://stackoverflow.com/questions/9141867/django-cms-app-hook-at-homepage-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!