Skip to content

django-url-pattern

Preview (since 0.2.10) · Related issues · View source

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for hardcoded internal URLs in HTML link attributes that should use Django's {% url %} template tag.

Why is this bad?

Hardcoded internal paths duplicate the routing configuration into every template and break silently when a urls.py entry is renamed or remounted. The {% url %} template tag resolves paths from named URL patterns at render time, so the template stays correct across refactors and respects URL namespacing (app_name, instance_namespace).

Example

<a href="/profile/">Profile</a>
<form action="/login/"></form>

Use instead:

<a href="{% url 'profile' %}">Profile</a>
<form action="{% url 'login' %}"></form>

References