Django-cms apphook url not loading

I have a django-cms project containing an application called core. Inside the kernel, I created the 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 /urls.py kernel, 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 am trying to achieve this view:

 url(r'^noticias/(?P<categoria>[\w\d-]+)/(?P<subcategoria>[\w\d-]+)/(?P<titulo>[\w\d-]+)/$', 'noticia.views.noticia'), 

Using this URL:

 http://127.0.0.1:8000/noticias/filmes/acao/lol-e-poka-zuera/ 

But urls.py is not loading Apphook. I have already set the Apphook field on each child page of "Noticias" and "Noticias". The strange thing is that I have the same structure in another project that works great. And, obviously, I installed the "core" application in INSTALLED_APPS. I just can't imagine what might cause this problem. I used a breakpoint in my kernel /urls.py, but was not called by Apphook.

+4
source share
3 answers
 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'), ) 
+2
source

Did you restart the server? (even if you use the manage.py management server, you need to restart it)

Next you should use RequestContext in your view. https://django.readthedocs.org/en/latest/ref/templates/api.html#subclassing-context-requestcontext

I just had a 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: Perhaps I skipped this question. The problem is that you are not getting any output with your app or that it is impossible to connect with it?

In the case of the second, perhaps django-cms: the URLs used by apphooks do not work with the return () or {% url%} , will help you.

EDIT 2 It just turned out that the current django-cms no longer has cms.middleware.multilingual.MultilingualURLMiddleware .

0
source

This is a design limitation, as OP commented. If the page has not been published yet, Django CMS will not load the apphooked view.
It still works (current version is 3.3.0), so to work on the apphook you need to publish this page.
There is a related issue in github: https://github.com/divio/django-cms/issues/2605

0
source

Source: https://habr.com/ru/post/1480861/


All Articles