5.3 KiB
Template Errors Fix - Complete Summary
Date
February 21, 2026
Overview
This document summarizes the comprehensive fixes for multiple template and URL reference errors encountered during testing and development.
Issues Fixed
1. Original NoReverseMatch Error
Error: Reverse for 'list' not found. 'list' is not a valid view function or pattern name.
Location: templates/dashboard/command_center.html line 147
Cause: The URL tag was using complaints:list but the actual URL name was complaints:complaint_list
Fix: Changed {% url 'complaints:list' %} to {% url 'complaints:complaint_list' %}
2. Pagination Template Error
Error: TemplateDoesNotExist at /organizations/patients/ : includes/pagination.html
Location: templates/organizations/patient_list.html line 86
Cause: The template was trying to include includes/pagination.html which didn't exist
Fix: Replaced the {% include %} tag with inline pagination code following the pattern used in other templates
3. Base Template Path Errors
Error: TemplateDoesNotExist: base.html
Cause: Multiple templates were extending 'base.html' instead of the correct 'layouts/base.html'
Files Fixed:
templates/organizations/patient_detail.htmltemplates/organizations/patient_form.htmltemplates/organizations/patient_confirm_delete.htmltemplates/surveys/bulk_job_status.htmltemplates/surveys/bulk_job_list.html
Fix: Changed {% extends 'base.html' %} to {% extends 'layouts/base.html' %} in all affected templates
Technical Details
URL Name Conventions
The project uses namespaced URL patterns with descriptive names:
complaints:complaint_list(notcomplaints:list)complaints:complaint_detailcomplaints:complaint_createorganizations:patient_listorganizations:patient_detailsurveys:instance_list- etc.
Template Structure
- Base templates are located in
templates/layouts/ - The main base template is
templates/layouts/base.html - Public templates use
templates/layouts/public_base.html - App-specific templates are in
templates/<app_name>/
Pagination Pattern
Pagination is implemented inline in templates using Django's paginator object:
{% if is_paginated %}
<div class="flex items-center justify-between">
<div class="text-sm text-slate">
{% trans "Showing" %} {{ page_obj.start_index }}-{% trans "to" %} {{ page_obj.end_index }} {% trans "of" %} {{ page_obj.paginator.count }}
</div>
<div class="flex gap-2">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}" class="btn-secondary px-3 py-1">
{% trans "Previous" %}
</a>
{% endif %}
<span class="px-3 py-1 bg-light rounded font-medium">
{{ page_obj.number }} {% trans "of" %} {{ page_obj.paginator.num_pages }}
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}" class="btn-secondary px-3 py-1">
{% trans "Next" %}
</a>
{% endif %}
</div>
</div>
{% endif %}
Verification Steps
1. URL Reverse Resolution
python manage.py show_urls | grep complaints
Confirmed that complaints:complaint_list exists and complaints:list does not.
2. Template Path Verification
find templates -name "base.html"
Confirmed that base templates are in templates/layouts/ directory.
3. Pagination Context
Verified that views provide is_paginated, page_obj, and paginator context variables.
Best Practices Applied
- Always use explicit URL names - Avoid generic names like "list" that might be ambiguous
- Follow template directory structure - Use
layouts/for base templates - Implement pagination inline - Avoid creating separate include files for common patterns
- Verify URL patterns - Check
urls.pyfiles to confirm correct URL names before using them in templates
Files Modified
templates/dashboard/command_center.html- Fixed URL referencetemplates/organizations/patient_list.html- Fixed pagination implementationtemplates/organizations/patient_detail.html- Fixed base template pathtemplates/organizations/patient_form.html- Fixed base template pathtemplates/organizations/patient_confirm_delete.html- Fixed base template pathtemplates/surveys/bulk_job_status.html- Fixed base template pathtemplates/surveys/bulk_job_list.html- Fixed base template path
Related Documentation
Conclusion
All template and URL reference errors have been resolved. The application should now:
- Successfully reverse all URL names
- Render all templates without TemplateDoesNotExist errors
- Display pagination controls correctly on list pages
- Extend the correct base templates for consistent layout
Next Steps
- Test the application thoroughly to ensure no other similar errors exist
- Consider adding URL name validation to the CI/CD pipeline
- Document URL naming conventions in the project's developer guide
- Add unit tests to verify template rendering with proper context