Lint Django templates with djLint and enable it as a prek hook
Maintainer thường phản hồi trong vòng 12 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- frontend, testing-qa, tooling
Hướng nghiên cứu
Start with the 13 templates listed in the issue and run uvx --from djlint==1.46.2 djlint pythonie --lint --profile=django to reproduce the reported findings. Then review pyproject.toml, .pre-commit-config.yaml, CONTRIBUTING.md, and CLAUDE.md for the shared configuration and hook documentation. Done means the lint and prek checks pass, the meetup sponsors and bundled theme script still work, and the listed test command succeeds.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Context
The repository runs its git hooks with prek (see .pre-commit-config.yaml, added in #249). The hooks cover Python (ruff, django-upgrade, Django checks, missing migrations) and generic files, but nothing checks the Django templates.
djLint is a linter and formatter for HTML templates with template syntax (Django profile). It was evaluated in #249 and left out because it does not pass on the current templates. This issue tracks fixing the templates and then enabling djLint as a prek hook.
Scope
13 templates:
pythonie/core/templates/404.html
pythonie/core/templates/500.html
pythonie/core/templates/base.html
pythonie/core/templates/footer.html
pythonie/core/templates/header.html
pythonie/core/templates/navbar.html
pythonie/core/templates/navbar_tree.html
pythonie/core/templates/core/home_page.html
pythonie/core/templates/core/meetup.html
pythonie/core/templates/core/segment.html
pythonie/core/templates/core/simple_page.html
pythonie/core/templates/core/sponsor.html
pythonie/templates/wagtailembeds/embed_frontend.html
Current state (djLint 1.46.2, master at 90cf69d)
uvx --from djlint==1.46.2 djlint pythonie --lint --profile=django reports 12 errors:
| File | Line | Rule | Message |
|---|---|---|---|
core/templates/500.html |
5 | H005 | <html> should have a non-empty lang attribute |
core/templates/base.html |
8 | H005 | <html> should have a non-empty lang attribute |
core/templates/base.html |
9, 45, 63 | H014 | Extra blank lines |
core/templates/base.html |
43, 44, 78 | H024 | Omit type on scripts and styles |
core/templates/core/meetup.html |
5 | H025 | Tag seems to be an orphan (<div class="col-md-12">) |
core/templates/header.html |
8 | H013 | <img> should have an alt attribute |
core/templates/navbar.html |
21, 22 | T001 | Tags should be wrapped in whitespace ({%include ...%}, {%endfor%}) |
djlint pythonie --check --profile=django reports that all 13 files would be reformatted (about 216 changed lines in total).
Real markup bugs in core/templates/core/meetup.html
The H025 warning points at actual bugs in the sponsor block of the meetup list:
- Line 24:
<div class="col-md-8">has a stray backtick, so the browser parses a brokenclassattribute and thecol-md-8` column class is not applied. <div class="name">(line 25) is never closed: 5<div>are opened inside the loop body (col-md-12,sponsor-list,sponsor,col-md-8,name) and only 4 are closed, so the browser closes the elements implicitly and the layout of the sponsor list depends on error recovery.
Tasks
Split the work into separate commits so the review stays easy:
1. Fix the lint errors (fix(templates): ...)
meetup.html: remove the stray backtick and close<div class="name">right after the sponsor name block (before the{% if sponsor.note %}caption, or after it if the caption belongs to the name block; check the rendering).base.htmland500.html: addlang="en"to<html>. In500.htmlthe<html>tag sits inside IE conditional comments (<!--[if ...]>); the non-IE branch (line 5) is the one djLint flags, addlang="en"to every branch for consistency (or drop the IE conditional comments, IE is no longer supported by Bootstrap/the site).header.html: addalt="Python Ireland"to the logo<img>.base.html: droptype="text/javascript"on the three<script>tags (lines 43, 44, 78). Line 78 is inside{% compress js %}: django-compressor handles scripts without atypeattribute as JavaScript, but verify it by rendering a page withCOMPRESS_ENABLED=True(or runningmanage.py compressif offline compression is used) and checking thattheme-toggle.jsis still bundled.navbar.html:{%include "navbar_tree.html" %}becomes{% include "navbar_tree.html" %},{%endfor%}becomes{% endfor %}.base.html: remove the extra blank lines.
After this commit, djlint pythonie --lint --profile=django must report 0 errors.
2. Reformat the templates (style(templates): ...), optional
Run djlint pythonie --reformat --profile=django and commit the result on its own. It changes whitespace and indentation only, but djLint also reflows some inline content (for example pythonie/templates/wagtailembeds/embed_frontend.html is collapsed to a single line), so check the rendered pages visually (home page, a simple page, the navbar with nested pages, the meetup list with sponsors, the 404 page).
If the formatter output is not acceptable on some templates, keep only the linter (task 3 without djlint-reformat-django) and mention it in the PR.
3. Configure djLint and enable the prek hook (chore(dev): ...)
-
Add the configuration to
pyproject.tomlso the CLI, the hook and editors share it:[tool.djlint] profile = "django" # ignore = "H030,H031" # only if some rules are deliberately skipped, with a comment explaining why -
Add the hooks to
.pre-commit-config.yaml, pinned on a tag (latest at the time of writing:v1.46.2, check withgh api repos/djlint/djLint/tags --jq '.[0].name'):- repo: https://github.com/djlint/djLint rev: v1.46.2 hooks: - id: djlint-reformat-django # only if task 2 is done - id: djlint-djangodjLint only targets
.htmlfiles by default. The vendored assets underpythonie/core/static/{css,fonts,js}are already excluded by the globalexcludeof the config. -
Nothing to change in CI: the
prekjob in.github/workflows/test.ymlruns every hook with--all-files. Renovate already updates the hook revisions (thepre-commitmanager is enabled inrenovate.json, grouped in the "pre-commit hooks" PR). -
Document djLint in the list of hooks in
CONTRIBUTING.md(section "Git Hooks (prek)") and inCLAUDE.md(section "Git Hooks (prek)").
Acceptance criteria
-
prek run --all-filespasses, djLint hooks included -
djlint pythonie --lint --profile=djangoreports 0 errors - The meetup list with sponsors renders correctly (the two bugs in
meetup.htmlare fixed) -
theme-toggle.jsis still loaded and bundled by django-compressor -
uv run python pythonie/manage.py test pythonie --settings=pythonie.settings.testspasses (run it withenv -u DATABASE_URLif aDATABASE_URLis exported in the shell, otherwise the test settings use that database) - The CI
prekandtestjobs are green - Separate commits for the fixes, the optional mass reformat and the hook configuration
Out of scope
- Redesigning the templates or upgrading Bootstrap.
base.htmlloads Typekit from//use.typekit.net/qgj1xay.js. Whether this kit still exists is worth checking, but in a separate issue.
- Ngôn ngữ chính
- Python
- Star
- 17
- Fork
- 27
- Merge trung bình
- 59 phút
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PythonIreland/website
-
PSF Grant -UrgentĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
PythonIreland/website#205 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Sponsorship Brochure- Urgent!Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
PythonIreland/website#204 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
dependencies enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
PythonIreland/website#187 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
dependencies enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
PythonIreland/website#184 · 8 bình luận ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
PythonIreland/website#177 ·
Maintainer thường phản hồi trong vòng 12 ngày
Tất cả issue của PythonIreland/website
Issue tương tự
-
pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pydantic/pydantic-ai#8843 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change enhancement server
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sktime/sktime#11310 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày