Django Helper
Django Helper adds project-aware URL/model navigation, Django ORM and template completions, hover details, diagnostics, and snippets to VS Code.
Requirements
- Node.js 18 or newer
- npm
- VS Code 1.85 or newer
- A Django workspace containing
manage.py
The setup scripts install dependencies (including native Tree-sitter modules), compile the extension, and create django-helper-0.0.1.vsix.
Linux / macOS
- Save
setup.sh to a directory where you want the extension project created.
- Run
chmod +x setup.sh.
- Run
./setup.sh.
- The project is created in
./django-helper; the VSIX is created in that directory.
Windows PowerShell
- Save
setup.ps1 to the directory where you want the project created.
- Open PowerShell in that directory.
- If script execution is blocked for the current session, run
Set-ExecutionPolicy -Scope Process Bypass.
- Run
.\setup.ps1.
Install the VSIX
From the generated project directory, run:
code --install-extension django-helper-0.0.1.vsix
Alternatively, use Extensions: Install from VSIX... in VS Code.
Verify it works
- Open a Django project folder that contains
manage.py.
- Ensure the project has a
settings.py, at least one models.py, and a urls.py.
- In
urls.py, add a named route such as path("books/", views.book_list, name="book-list").
- In a template, type
{% url 'book-list' %}. Use Ctrl+Click or F12 on the name to navigate to the route; hovering shows its pattern and resolved view when available.
- In a model, define a relation such as
author = models.ForeignKey("Author", on_delete=models.CASCADE). Ctrl+Click the quoted model name.
- In Python, type
Book.objects. and inspect QuerySet completions. In a template, type {% or {% url '.
- Add a POST form without
{% csrf_token %} and confirm the warning. Add an unknown URL name and confirm the error.
- Run Django Helper: Reindex Django Project from the Command Palette after making structural changes if needed.
Features
- F12 / Ctrl+Click for URL names in Django
{% url %}, Python reverse() / redirect(), and quoted model relations.
- Model field extraction and model-name hover information.
- QuerySet methods, field lookup suffixes, model fields, URL names, template tags, and model import completions.
- Unknown template URL and POST-without-CSRF diagnostics; basic ORM keyword-field diagnostics.
- Python and HTML snippets for common Django patterns.
- Automatic activation only when the first workspace folder contains
manage.py.
- Debounced indexing when Python and template files change.
Known limitations
- The indexer targets the first workspace folder and conventional Django project layouts. Monorepos with multiple independent Django roots should open each root separately.
INSTALLED_APPS and TEMPLATES[...]["DIRS"] are extracted from straightforward literal settings assignments; dynamically assembled settings, environment-driven paths, and custom settings loaders may not be resolved.
- URL extraction supports common
path() and re_path() declarations. Complex nested includes, namespaced URL reversing, dynamically generated patterns, and decorators that obscure view targets may not resolve.
- View resolution uses indexed class/function names and can be ambiguous when several apps define the same name.
- Model parsing handles conventional model classes and direct
models.Field(...) assignments. Abstract inheritance, dynamically generated fields, proxy models, custom field aliases, and fields declared through mixins are not fully represented.
- ORM field diagnostics use the union of discovered model fields because static inference of the queryset's model is not generally reliable; this can produce false positives or miss errors.
- Template diagnostics cover simple quoted URL names and literal POST form tags. JavaScript-generated forms, unusual HTML nesting, and dynamically assembled template tags are not analyzed.
- Tree-sitter packages include native binaries for the platform on which
npm install runs. Build/package on the target operating system and architecture for best compatibility.
- VS Code's built-in HTML language mode is used for
.html files; the snippets are also registered for django-html.
This extension provides static assistance; it does not replace Django's runtime checks, tests, or framework documentation.
| |