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

[BUG] placeholders-outside-cms TemplateDoesNotExist #7892

Open
1 of 2 tasks
openHBP opened this issue Apr 26, 2024 · 3 comments
Open
1 of 2 tasks

[BUG] placeholders-outside-cms TemplateDoesNotExist #7892

openHBP opened this issue Apr 26, 2024 · 3 comments

Comments

@openHBP
Copy link

openHBP commented Apr 26, 2024

Description

https://docs.django-cms.org/en/latest/how_to/01-placeholders.html#placeholders-outside-cms

Following the steps described "structure mode template" does not work.
Django does not find the template in any places: root templates folder, myapp/templates, myapp/templates/myapp

django.template.exceptions.TemplateDoesNotExist

Additional information (CMS/Python/Django versions)

  • Django==3.2.25
  • django-cms==4.1.0
  • Python==3.10

Do you want to help fix this issue?

  • Yes, I want to help fix this issue and I will join #workgroup-pr-review on Slack to confirm with the community that a PR is welcome.
  • No, I only want to report the issue.
@fsbraun
Copy link
Sponsor Member

fsbraun commented Apr 26, 2024

Hi @openHBP ! Can you double-check your get_template() result and the template folders? I cannot reproduce this.

If get_template() returns "my_app/my_model_structure.html" the typical place for the template would be my_app/templates/my_app/my_model_structure.html.

@openHBP
Copy link
Author

openHBP commented Apr 29, 2024

The template is indeed in my_app/templates/my_app/my_model_structure.html where my_app is msg
image

Content of msg.models.py

from cms.models.fields import PlaceholderRelationField
from cms.utils.placeholder import get_placeholder_from_slot

...
short_text3 = PlaceholderRelationField()
...

    def my_placeholder(self):
        return get_placeholder_from_slot(self.short_text3, "msgdet_slot")

    def get_template(self):
        return "msg/msgdet_model_structure.html"

Apart from that everything works fine. I can edit the placeholder text as if it was in the CMS

Here is the error (where /chapeau is the /admin path)

File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/library.py", line 192, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/cms/templatetags/cms_js_tags.py", line 36, in render_cms_structure_js
    obj_placeholders_by_slot = rescan_placeholders_for_obj(obj)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/cms/utils/placeholder.py", line 352, in rescan_placeholders_for_obj
    declared_placeholders = get_declared_placeholders_for_obj(obj)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/cms/utils/placeholder.py", line 374, in get_declared_placeholders_for_obj
    return get_placeholders(obj.get_template())
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/cms/utils/placeholder.py", line 252, in get_placeholders
    compiled_template = get_template(template)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/loader.py", line 19, in get_template
    raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: /msg/msgdet_model_structure.html

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/cms/views.py", line 263, in render_object_structure
    return render(request, 'cms/toolbar/structure.html', context)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/backends/django.py", line 63, in render
    reraise(exc, self.backend)
  File "/home/pat/dev/pipenv/cpilote2/.venv/lib/python3.10/site-packages/django/template/backends/django.py", line 84, in reraise
    raise new from exc
django.template.exceptions.TemplateDoesNotExist: /msg/msgdet_model_structure.html
[29/Apr/2024 12:13:56] "GET /chapeau/cms/placeholder/object/53/structure/1271/ HTTP/1.1" 500 260510

@fsbraun
Copy link
Sponsor Member

fsbraun commented Apr 29, 2024

When does the error happen? I would assume that the structure view is necessary to edit the content. So if that works, the template should be found. Maybe it is accessed elsewhere, too?

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

No branches or pull requests

2 participants