Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error at root url without trailing slash #793

Open
palmitoto opened this issue Feb 13, 2024 · 12 comments
Open

Error at root url without trailing slash #793

palmitoto opened this issue Feb 13, 2024 · 12 comments

Comments

@palmitoto
Copy link

Description

When I go to the blog root page without the trailing slash, I get an Internal Server Error.

Steps to reproduce

Go to the blog root url without the / at the end.

Versions

Python 3.11
Django 4.2.10
django-cms-blog 2
django-cms 3.11

Expected behavior

Redirect to /fr/blog/

Actual behaviour

I get an Internal Server Error :

Report at /fr/blog
Internal Server Error: /fr/blog
Traceback (most recent call last): None

Additional information

I don't have this problem for an article url.
I also don't have the problem if I switch back to Django 3.2.
I also don't have the problem if debug=True
APPENS_SLASH settings are set to True

@protoroto
Copy link
Member

@palmitoto Hi! Thanks for reporting this! Do you have some sort of traceback of the error? I can't reproduce it (for example, here https://www.nephila.digital/en/blog , ther's a blog instance of DjangoCMS Blog).

@palmitoto
Copy link
Author

Hi, thanks for your time!

This my stack :

Resolver404: {'tried': [[<URLResolver <module 'loginas.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/loginas/urls.py'> (None:None) 'kapt/'>], [<URLResolver <URLPattern list> (admin:admin) 'kapt/'>], [<URLResolver <module 'django_select2.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/django_select2/urls.py'> (django_select2:django_select2) 'select2/'>], [<URLResolver <module 'libs.emails.test.urls' from '/home/kapt/workspace/my_project/src/libs/emails/test/urls.py'> (None:None) 'test-mail/'>], [<URLResolver <module 'cookie_optin.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/cookie_optin/urls.py'> (cookie_optin:cookie_optin) 'cookie-optin/'>], [<URLResolver <module 'taggit_autosuggest.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/taggit_autosuggest/urls.py'> (None:None) 'taggit_autosuggest/'>], [<URLResolver <module 'fobi.urls.view' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/fobi/urls/v...
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 181, in _get_response
    callback, callback_args, callback_kwargs = self.resolve_request(request)
  File "django/core/handlers/base.py", line 313, in resolve_request
    resolver_match = resolver.resolve(request.path_info)
  File "django/urls/resolvers.py", line 702, in resolve
    raise Resolver404({"tried": tried, "path": new_path})
Resolver404: {'tried': [[<URLResolver <module 'loginas.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/loginas/urls.py'> (None:None) 'kapt/'>], [<URLResolver <URLPattern list> (admin:admin) 'kapt/'>], [<URLResolver <module 'django_select2.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/django_select2/urls.py'> (django_select2:django_select2) 'select2/'>], [<URLResolver <module 'libs.emails.test.urls' from '/home/kapt/workspace/my_project/src/libs/emails/test/urls.py'> (None:None) 'test-mail/'>], [<URLResolver <module 'cookie_optin.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/cookie_optin/urls.py'> (cookie_optin:cookie_optin) 'cookie-optin/'>], [<URLResolver <module 'taggit_autosuggest.urls' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/taggit_autosuggest/urls.py'> (None:None) 'taggit_autosuggest/'>], [<URLResolver <module 'fobi.urls.view' from '/home/kapt/workspace/my_project/.venv/lib/python3.11/site-packages/fobi/urls/v...
  File "django/core/handlers/exception.py", line 164, in get_exception_response
    response = callback(request, exception=exception)
  File "django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "django/views/defaults.py", line 64, in page_not_found
    body = template.render(context, request)
  File "django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "django/template/base.py", line 175, in render
    return self._render(context)
  File "django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "classytags/core.py", line 142, in render
    return str(self.render_tag(context, **kwargs))
  File "sekizai/templatetags/sekizai_tags.py", line 87, in render_tag
    rendered_contents = nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "classytags/core.py", line 142, in render
    return str(self.render_tag(context, **kwargs))
  File "cms/templatetags/cms_tags.py", line 433, in render_tag
    return nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 208, in render
    return template.render(context)
  File "django/template/base.py", line 177, in render
    return self._render(context)
  File "django/template/base.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 541, in render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "classytags/core.py", line 142, in render
    return str(self.render_tag(context, **kwargs))
  File "classytags/helpers.py", line 88, in render_tag
    flatten_context(self.get_context(context, **kwargs))
  File "menus/templatetags/menu_tags.py", line 141, in get_context
    nodes = menu_renderer.get_nodes(namespace, root_id)
  File "django/utils/functional.py", line 150, in __wrapper__
    return getattr(res, method_name)(*args, **kw)
  File "menus/menu_pool.py", line 234, in get_nodes
    nodes = self.apply_modifiers(
  File "menus/menu_pool.py", line 228, in apply_modifiers
    nodes = inst.modify(
  File "djangocms_blog/cms_menus.py", line 185, in modify
    namespace = resolve(request.path).namespace
  File "django/urls/base.py", line 24, in resolve
    return get_resolver(urlconf).resolve(path)
  File "django/urls/resolvers.py", line 702, in resolve
    raise Resolver404({"tried": tried, "path": new_path})

@protoroto
Copy link
Member

This is strange: do you have "django.middleware.common.CommonMiddleware" in your project MIDDLEWARE settings?

@palmitoto
Copy link
Author

palmitoto commented Feb 15, 2024

Yes:

MIDDLEWARE = (
    "django.middleware.security.SecurityMiddleware",
    "django.middleware.gzip.GZipMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.locale.LocaleMiddleware",
    "django.middleware.http.ConditionalGetMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.contrib.sites.middleware.CurrentSiteMiddleware",
)

@protoroto
Copy link
Member

Do you have some custom context processor trying to resolve urls? Because in any case this should throw a 500 error: it should throw a 404 if it can't resolve urls. Are you able to reproduce this with a fresh djangocms 3.11 and djangocms-blog installation?

@palmitoto
Copy link
Author

palmitoto commented Feb 15, 2024

On a fresh install from django-cms boilerplate, i get a 404. So I will compare with my settings to find the error.

How do you handle this case (404) on nephila blog? Put a redirection ?

@protoroto
Copy link
Member

On nephila blog, both urls works correctly (with or without trailing slash). This should be the case for ALL urls, given that the urlconf is done correctly. In this case the Blog apphook, attached to the page, should leverage all the work, unless I'm missing some configuration that I don't know.
I'm sorry I can't be of more help here :(

@palmitoto
Copy link
Author

Thank @protoroto for all the time spent, which has already helped me move forward.

@febsn
Copy link

febsn commented Oct 7, 2024

@palmitoto have you been able to resolve this? I'm facing the same issue after upgrading to Django 4.2, and only getting Traceback: None.

@febsn
Copy link

febsn commented Oct 7, 2024

I've come a little closer. My 404 template used the menu_tags library to display navigation. When I remove it (and the corresponding tags) the redirect works. Seems like the 404 is raised at a stage where, for some reason, it can't use navigation tags from the cms, and django tries some template rendering before the 404 is caught by CommonMiddleware (somewhere around https://github.com/django/django/blob/6f9fea33137fee6416ff43b775aa9567440a23d3/django/middleware/common.py#L69).

I'm still not sure how to resolve this, since a 404 without navigation isn't of much use. Any detailed ideas what's going here?

@palmitoto
Copy link
Author

The error was very isolated I did not look further. But recently on a new site we had the same error and the "solution" was to remove the menus from the 404 page...

@febsn
Copy link

febsn commented Oct 26, 2024

I've just encountered the same problem with another (custom-built) apphook. So I'd assume it's not djangocms-blog. I'm going to file an issue in django-cms when I have time (but please go ahead if you'd like to).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants