Troubleshooting¶
Common issues and solutions when working with Django IncludeContents.
Template Errors¶
TemplateDoesNotExist¶
Error:
Causes and Solutions:
-
Component file doesn't exist:
Solution: Create the component file in the correct location. -
Incorrect file path:
Solution: Use kebab-case and ensure the filename matches. -
Missing components directory:
-
Template engine not configured:
TemplateSyntaxError¶
Error:
Solution: Load the template tag library:
{% load includecontents %}
{% includecontents "components/card.html" %}
Content
{% endincludecontents %}
Error:
Common causes:
-
Missing template name:
-
Incorrect attribute syntax:
Component Issues¶
Empty Component Content¶
Problem: Component renders but shows no content.
Debug steps:
-
Check props are being passed:
-
Verify context isolation:
-
Check for typos in variable names:
Missing Required Attributes¶
Error:
Solution: Provide all required attributes:
<!-- Component definition -->
{# props title, description="" #}
<!-- ❌ Wrong: missing required title -->
<include:card description="A card">Content</include:card>
<!-- ✅ Correct: title provided -->
<include:card title="My Card" description="A card">Content</include:card>
Variable Not Found in Component¶
Problem: Variables show as empty in component templates.
Debugging:
-
Check context isolation:
-
Solution - pass variables explicitly:
HTML Syntax Issues¶
HTML Components Not Working¶
Problem: HTML component syntax doesn't work, shows as literal text.
Check your template engine:
# settings.py
TEMPLATES = [{
'BACKEND': 'includecontents.django.Engine', # Required for HTML syntax
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
# ...
}]
Common issues:
-
Wrong template engine:
-
File not in components directory:
Self-Closing Tags Not Working¶
Problem:
Solution: Ensure proper self-closing syntax:
<!-- ✅ Correct -->
<include:icon name="star" />
<!-- ❌ Wrong - missing space before / -->
<include:icon name="star"/>
Performance Issues¶
Slow Template Rendering¶
Problem: Templates render slowly with many components.
Solutions:
-
Enable template caching:
-
Avoid heavy computation in components:
<!-- ❌ Slow: complex calculations in template --> {# props user #} {% for post in user.posts.all %} {% for comment in post.comments.select_related.all %} <!-- Complex nested queries --> {% endfor %} {% endfor %} <!-- ✅ Fast: pass computed data --> {# props user, user_stats #} <div>Posts: {{ user_stats.post_count }}</div> <div>Comments: {{ user_stats.comment_count }}</div>
-
Use conditional rendering:
Development Issues¶
Component Changes Not Reflected¶
Problem: Component template changes don't appear in browser.
Solutions:
-
Disable template caching during development:
-
Clear template cache:
-
Check file paths:
IDE Not Recognizing Components¶
Problem: No syntax highlighting or autocomplete for components.
Solutions:
-
VS Code setup:
-
Configure file associations:
- Associate
.html
files with Django HTML language mode - Install Django extensions for your IDE
Error Debugging¶
Enable Debug Mode¶
Template debugging:
Verbose error output:
# Add to component template for debugging
{# props title, description="" #}
<div>
<h1>DEBUG: title="{{ title }}"</h1>
<p>DEBUG: description="{{ description }}"</p>
<div>DEBUG: contents="{{ contents }}"</div>
</div>
Common Error Patterns¶
1. Context variable naming:
<!-- ❌ Wrong: underscore vs hyphen confusion -->
<include:user-card user_name="{{ user.name }}"> <!-- prop: user_name -->
<!-- Component expects: {{ user-name }} not {{ user_name }} -->
<!-- ✅ Correct: consistent naming -->
<include:user-card user-name="{{ user.name }}"> <!-- prop: user-name -->
<!-- Component uses: {{ user-name }} -->
2. Quote handling:
<!-- ❌ Wrong: nested quotes -->
<include:card title="Say "Hello"">
<!-- ✅ Correct: escaped quotes -->
<include:card title="Say "Hello"">
<!-- ✅ Alternative: different quote types -->
<include:card title='Say "Hello"'>
Getting Help¶
Before Asking for Help¶
- Check this troubleshooting guide
- Enable debug mode
- Create a minimal reproduction case
- Check recent changes to your templates
When Reporting Issues¶
Include this information:
-
Django IncludeContents version:
-
Django version:
-
Template engine configuration:
-
Minimal code example:
-
Full error traceback:
Community Resources¶
- GitHub Issues: Bug reports and feature requests
- Documentation: Complete feature documentation
- Examples: Working code examples
Prevention Tips¶
Best Practices to Avoid Issues¶
- Use consistent naming conventions
- Document component props clearly
- Test components in isolation
- Keep components simple and focused
- Use template debugging during development
Regular Maintenance¶
- Update Django IncludeContents regularly
- Run tests after updates
- Review component usage patterns
- Clean up unused components
Still Having Issues?¶
If this guide doesn't solve your problem:
- Search existing issues
- Create a new issue with:
- Clear problem description
- Minimal reproduction steps
- Environment details
- Error messages or unexpected behavior