Reputation: 3079
I have a django-cms project that contains an app called core. Inside core I created a file "cms_app.py" as follows:
# -*- coding: utf8 -*-
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
class CoreApphook(CMSApp):
name = _(u"Core Apphook")
urls = ["core.urls"]
apphook_pool.register(CoreApphook)
In my core/urls.py I have the following code:
# -*- coding: utf8 -*-
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
# URLS refrentes ao apphook CoreApphook
url(r'^$', 'noticia.views.ultimas_noticias'),
url(r'^noticias/$', 'noticia.views.ultimas_noticias'),
url(r'^noticias/(?P<categoria>[\w\d-]+)/$', 'noticia.views.noticias_categoria'),
url(r'^noticias/(?P<categoria>[\w\d-]+)/(?P<pagina>\d+)/$', 'noticia.views.noticias_categoria_paginated'),
url(r'^noticias/(?P<categoria>[\w\d-]+)/(?P<subcategoria>[\w\d-]+)/(?P<titulo>[\w\d-]+)/$', 'noticia.views.noticia'),
url(r'^paginacao/noticias/$', 'noticia.views.noticias_categoria_paginated'),
)
I'm trying to reach this view:
url(r'^noticias/(?P<categoria>[\w\d-]+)/(?P<subcategoria>[\w\d-]+)/(?P<titulo>[\w\d-]+)/$', 'noticia.views.noticia'),
By using this url:
http://127.0.0.1:8000/noticias/filmes/acao/lol-e-poka-zuera/
But the file urls.py is not loaded by the Apphook. I've already set the Apphook field in every child page of "Noticias" and "Noticias" as well. The weird thing about it is that I have the same structure in another project which works perfectly. And obviously I've set the app "core" into INSTALLED_APPS. I just can't even imagine what may be causing this issue. I've used a breakpoint into my core/urls.py, but It's not being called by the Apphook.
Upvotes: 5
Views: 2242
Reputation: 1463
It's a design limitation, as the OP commented. If the page is not published yet Django CMS won't load the apphooked view.
It still works like that (current version is 3.3.0), so to make the apphook work you need to publish the page.
There's a related issue on github: https://github.com/divio/django-cms/issues/2605
Upvotes: 0
Reputation: 370
Have you restarted the server? (even if you use the manage.py runserver you have to restart it)
Further on you have to use RequestContext in your view. https://django.readthedocs.org/en/latest/ref/templates/api.html#subclassing-context-requestcontext
I just had the problem and the following helped:
from django.shortcuts import render_to_response
from django.template import RequestContext
def some_view(request):
# ...
return render_to_response('my_template.html',
my_data_dictionary,
context_instance=RequestContext(request))
EDIT: Maybe i miss understood the question. Is the problem that you don't get any output with your apphook or that it is not possible to link to it?
In case of the second, maybe django-cms: urls used by apphooks don't work with reverse() or {% url %} helps you.
EDIT 2 Just found out that the current django-cms does not have the cms.middleware.multilingual.MultilingualURLMiddleware
anymore.
Upvotes: 0
Reputation: 21
urlpatterns = patterns('',
# URLS refrentes ao apphook CoreApphook
url(r'^$', 'noticia.views.ultimas_noticias', name='app_ultimas_noticias'),
url(r'^noticias/$', 'noticia.views.ultimas_noticias', name='app_ultimas_noticias1'),
)
Upvotes: 2