DjangoCMS模板占位符未在结构视图显示问题排查求助
Hey there, let's work through why your Django CMS placeholders aren't appearing in the structure view. I've debugged this exact issue plenty of times, so here are the key checks to run through:
Verify placeholder tags are properly added to your templates
Make sure you've defined placeholders using the correct template tags in your base or child templates. For regular placeholders, use{% placeholder "your_placeholder_name" %}; for static placeholders, use{% static_placeholder "static_placeholder_name" %}. Double-check that the placeholder name matches what you expect to see in the structure view.Confirm your
CMS_TEMPLATESsetting is correct
Head tosettings.pyand ensure yourCMS_TEMPLATESlist is formatted properly. Each entry should be a tuple with the template path and a human-readable name, like this:CMS_TEMPLATES = [ ('base.html', 'Base Template'), ('pages/home.html', 'Home Page Template'), ]Also, when creating or editing a page in the CMS admin, make sure you've selected the template that actually contains your placeholders—it's easy to accidentally pick the wrong one!
Check template inheritance setup
If you're using child templates that extendbase.html, confirm:- The
{% extends "base.html" %}tag is the very first line in your child template (no leading HTML, spaces, or comments before it). - You aren't accidentally overriding the section of
base.htmlwhere your placeholders live in the child template. - Child templates include their own
{% load cms_tags sekizai_tags %}tags (though inheriting from base should handle this, it never hurts to double-check).
- The
Ensure Sekizai blocks are present
Django CMS relies on Sekizai to load critical frontend resources for the structure view. Inbase.html, make sure you have these blocks in the right places:<!-- In the <head> section --> {% render_block "css" %} <!-- Right before closing </body> tag --> {% render_block "js" %}Missing these blocks can break the CMS's admin UI, including placeholder rendering.
Clear caches
Caching is a frequent culprit here. Try:- Running
python manage.py clearcacheto clear Django's server-side cache. - Doing a hard refresh of your browser (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on Mac) to bypass client-side cache.
- Logging out and back into the CMS admin after clearing caches.
- Running
Check user permissions
Make sure the admin user you're logged in with has the necessary permissions to edit page structure. Specifically, verify they have thecms.change_pagepermission and access to the placeholder-related permissions (likecms.edit_placeholder).Validate template loading
Confirm Django is actually loading your templates correctly. Add a piece of test text (like<!-- TEST TEMPLATE LOADED -->) to your base or child template, then visit the frontend page to see if it appears. If not, check yourTEMPLATESsetting insettings.pyto ensure your template directory is included inDIRSor thatAPP_DIRSis set correctly for apps containing templates.
If none of these fixes work, try temporarily disabling any custom Django CMS plugins or third-party apps to rule out conflicts.
内容的提问来源于stack exchange,提问作者Dennis Gathagu

