question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found.

See original GitHub issue

I made a simple local test. Pages looks like this:

snapshot1

I request /de/blog/ and get the error:

Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['en/(?P<slug>[0-9A-Za-z-_.//]+)/$']

The blog page looks like this:

snapshot2

snapshot3

snapshot4

So you see, the EN title & slug is empty. But the page is published in de and en. Maybe this is the error? But this should not happen, isn’t it?

complete traceback:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/de/blog/?edit&language=de

Django Version: 1.7.4
Python Version: 3.4.0
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.staticfiles',
 'django.contrib.messages',
 'cms',
 'djangocms_admin_style',
 'djangocms_text_ckeditor',
 'menus',
 'sekizai',
 'mptt',
 'djangocms_file',
 'djangocms_link',
 'djangocms_picture',
 'djangocms_video',
 'cmsplugin_htmlsitemap',
 'cmsplugin_pygments',
 'reversion',
 'reversion_compare',
 'compressor',
 'django_extensions',
 'filer',
 'easy_thumbnails',
 'cmsplugin_filer_image',
 'parler',
 'taggit',
 'taggit_autosuggest',
 'django_select2',
 'meta',
 'meta_mixin',
 'admin_enhancer',
 'djangocms_blog',
 'django_info_panel',
 'pylucid',
 'example_project',
 'debug_toolbar',
 'pylucid_migration')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
 'cms.middleware.language.LanguageCookieMiddleware')


Template error:
In template /home/jens/page_instance_sqlite/example_project/templates/base.html, error at line 24
   Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['en/(?P<slug>[0-9A-Za-z-_.//]+)/$']
   14 :     <title>{% block title %}{% page_attribute page_title %}{% if site_settings.site.name %} - {{ site_settings.site.name }}{% endif %}{% endblock title %}</title>


   15 : 


   16 :     {% compress css %}


   17 :         <link href="{% static "css/bootstrap.min.css" %}" rel="stylesheet">


   18 :         <link href="{% static "css/styles.css" %}" rel="stylesheet">


   19 :     {% endcompress %}


   20 :     {% render_block "css" %}


   21 :   </head>


   22 : 


   23 :   <body>


   24 :      {% cms_toolbar %} 


   25 :     <div class="container">


   26 : 


   27 :       <!-- Static navbar -->


   28 :       <div class="navbar navbar-default" role="navigation">


   29 :         <div class="container-fluid">


   30 :           <div class="navbar-header">


   31 :             <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">


   32 :               <span class="sr-only"></span>


   33 :               <span class="icon-bar"></span>


   34 :               <span class="icon-bar"></span>


Traceback:
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  137.                 response = response.render()
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/response.py" in render
  103.             self.content = self.rendered_content
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/response.py" in rendered_content
  80.         content = template.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/base.py" in render
  148.             return self._render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/test/utils.py" in instrumented_test_render
  88.     return self.nodelist.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/test/utils.py" in instrumented_test_render
  88.     return self.nodelist.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/classytags/core.py" in render
  106.         return self.render_tag(context, **kwargs)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/sekizai/templatetags/sekizai_tags.py" in render_tag
  79.         rendered_contents = nodelist.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/classytags/core.py" in render
  106.         return self.render_tag(context, **kwargs)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/templatetags/cms_tags.py" in render_tag
  665.             toolbar.populate()
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/toolbar/toolbar.py" in populate
  238.         self._call_toolbar('populate')
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/toolbar/toolbar.py" in _call_toolbar
  285.                 result = getattr(toolbar, func_name)()
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/cms_toolbar.py" in populate
  107.         self.add_language_menu()
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/cms_toolbar.py" in add_language_menu
  179.                     url = DefaultLanguageChanger(self.request)(code)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/menus/utils.py" in __call__
  144.         return '%s%s' % (self.get_page_path(lang), self.app_path)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/menus/utils.py" in get_page_path
  111.                         return page.get_absolute_url(language=lang, fallback=True)
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/cms/models/pagemodel.py" in get_absolute_url
  162.         return reverse('pages-details-by-slug', kwargs={"slug": path})
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse
  551.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/jens/PyLucid_env/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  468.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /de/blog/
Exception Value: Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['en/(?P<slug>[0-9A-Za-z-_.//]+)/$']

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
wanaryytelcommented, Jul 11, 2018

This still happens when you call get_absolute_url from shell when you have multilang slugs and you don’t specify a language for the method.

    def get_absolute_url(self, language=None, fallback=True):
        if not language:
            language = get_language()
        with i18n.force_language(language):
            if self.is_home:
                return reverse('pages-root')
            path = self.get_path(language, fallback) or self.get_slug(language, fallback)
            return reverse('pages-details-by-slug', kwargs={"slug": path})

The get_language() is supposed to be a fallback, but get_language() returns None in shell for understandable reasons. I would reopen this and add a check for the case where get_language() returns nothing.

1reaction
eimsbushcommented, Jan 10, 2020

I could fix this by adding fallback languages to the cms-language settings. You need at least your primary language as fallback to the foreign languages in order to ne able to render the toolbar. For me site 3 had the problem. When you always edit and create english pages you need to put english to all other languages as fallback.

CMS_LANGUAGES = {
    'default': {
        'public': True,
        'redirect_on_fallback': False,
        'hide_untranslated': False,
    },
    1: [
        {
            'code': 'de',
            'name': 'Deutsch',
            'fallbacks': ['en', ],
        },
        {
            'code': 'en',
            'name': 'English',
            'fallbacks': ['de', ],
        },
        {
            'code': 'fr',
            'name': 'Français',
            'fallbacks': ['en', 'de'],
        },
        {
            'code': 'it',
            'name': 'Italiano',
            'fallbacks': ['en', 'fr', 'de'],
        },
    ],
    2: [
        {
            'code': 'es',
            'name': 'Español',
        },
    ],
    3: [
        {
            'code': 'de',
            'name': 'Deutsch',
            'fallbacks': ['en', ],
        },
        {
            'code': 'en',
            'name': 'English',
            'fallbacks': ['de', ],
        },
        {
            'code': 'fr',
            'name': 'Français',
            'fallbacks': ['en', 'de'],
        },
        {
            'code': 'it',
            'name': 'Italiano',
            'fallbacks': ['en', 'fr', 'de'],
        },
        {
            'code': 'nl',
            'name': 'Nederlands',
            'fallbacks': ['en', 'fr', 'de'],
        },
        {
            'code': 'bg',
            'name': 'български',
            'fallbacks': ['en', 'fr', 'de'],
        },
        {
            'code': 'da',
            'name': 'Dansk',
            'fallbacks': ['en', 'fr', 'de'],
        },
    ],
}```
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reverse for 'detail' with keyword arguments '{'slug': 'hello ...
When I used bellow RegEx to use as slug for details url I am getting this error. Would someone help me please to...
Read more >
Reverse for 'pages-details-by-slug' with arguments ... - GitHub
I made a simple local test. Pages looks like this: I request /de/blog/ and get the error: Reverse for 'pages-details-by-slug' with arguments ......
Read more >
reverse() function doesn't seem to take account of the includer ...
I have a urlconf being included from the top-level urlconf. the one being included is named, and I'm trying to get the reverse()...
Read more >
Django Slug Tutorial | LearnDjango.com
How to add URL slugs to a Django project. ... We need to change that over to a keyword argument, kwargs , for...
Read more >
Reverse for 'list' with arguments '()' and keyword ... - Treehouse
Reverse for 'list' with arguments '()' and keyword arguments '{}' not found. ... urlpatterns += staticfiles_urlpatterns(). app urls.py.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found