Django-cms email addresses not working with reverse () using python shell

I have created django CMS apphook. Unfortunately I am unable to reverse the apphook urls using the Python shell.

The file cms_app.py

looks like this:

class ArticleApp (CMSApp):
    name = _('Article App')
    app_name = 'article_app'
    urls = ['article.urls']

apphook_pool.register(ArticleApp)

      

This is my file urls.py

:

urlpatterns = patterns('',
    url(r'^(?P<slug>[\w\-]+)?', ArticleView.as_view(), name='article-by-slug'),
)

      

Template file:

{% url 'article_app:article-by-slug' article.slug %}

      

Moving the URL within the template works as expected. If I try to do the same using the Python shell, I get the error:

>>> from django.core.urlresolvers import reverse
>>> from article.models import Article
>>> a = Article.objects.get(pk=1)
>>> reverse('article_app:article-by-slug', kwargs={'slug': a.slug})
# Reverse for 'article_app:article-by-slug' with arguments '()' and keyword arguments '{'slug': 'this-is-article-1'}' not found.

      

Additional URLs defined mostly urls.py

work as expected from within the shell. Apphook urls alone don't work.

Any suggestions?

Thank!

+3


source to share


2 answers


Thanks to @Benjamin Wohlwend I was able to resolve the issue. The apphook page is not available in the "en-us" language (default for Django control commands such as "shell"). I had to activate the correct language before reverse:



from django.utils import translation
translation.activate('de')

      

+2


source


remove the namespace from the back side:



reverse('article-by-slug', kwargs={'slug': a.slug})

      

0


source







All Articles