Fix: CSS static files folder structure to follow Django best practices #1870
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Statement
The current tutorial instructs users to place CSS files at
blog/static/css/blog.css
, which violates Django's static files namespacing conventions and causes deployment issues.Impact:
python manage.py collectstatic
fails during deploymentSolution
Updated the CSS section and all related tutorial sections to follow Django's recommended static file structure:
app_name/static/app_name/
.Changes Made
blog/static/css/
→blog/static/blog/css/
{% static 'css/blog.css' %}
→{% static 'blog/css/blog.css' %}
across all tutorial sectionsDjango Static Files Convention
Following Django's standard structure:
app_name/static/app_name/[css|js|img|fonts]/
This prevents namespace collisions when multiple apps have files with the same name.
This structure ensures that python manage.py collectstatic correctly gathers and organizes all static files into a central directory . This is especially important on platforms like PythonAnywhere, where the main project uses the collected static files.
Files Modified
css/README.md
- Main CSS tutorial section (structure and explanation)template_extending/README.md
- Updated static CSS referencedjango_forms/README.md
- Updated static CSS referenceReferences
collectstatic
CommandAcceptance Criteria
app_name/static/app_name/
structureDeployment Impact
This change ensures:
collectstatic
works correctly in productionScope of Changes
This is a comprehensive fix that addresses the static file structure issue throughout the entire tutorial, ensuring: