cookiecutter-django icon indicating copy to clipboard operation
cookiecutter-django copied to clipboard

[BUG] PyCharm Integration with django-cookiecutter

Open urzbs opened this issue 7 months ago • 4 comments

Description:

We recently migrated a substantial project to the django-cookiecutter framework. Following this transition, we encountered significant issues with our IDE (PyCharm). Specifically, autocompletion within HTML templates stopped functioning correctly. This affected template tags such as {% include ... %} and {% static ... %}, which has been quite disruptive.

Initially, we mitigated the problem for the {% include ... %} tag by marking template directories as "Template Directories." However, this solution did not resolve issues related to {% static ... %}.

Investigation:

We suspected that our project-specific configurations might be causing these issues. However, upon testing with an empty django-cookiecutter project, we found that the problem persisted. This led us to conclude that PyCharm's Django integration might be struggling to detect the Django structure in projects created with django-cookiecutter.

To pinpoint the issue, we incrementally recreated the cookiecutter setup to observe when PyCharm's integration failed. We identified the following line in local.py as the culprit:

INSTALLED_APPS = ["whitenoise.runserver_nostatic", *INSTALLED_APPS]

It appears that PyCharm is unable to handle the unpacking operation when reading the INSTALLED_APPS list. Therefore leading to "no apps found" PyCharm message.

Solution:

By modifying the INSTALLED_APPS assignment as shown below, PyCharm's Django integration functions correctly, and autocompletion is restored:

INSTALLED_APPS.insert(0, "whitenoise.runserver_nostatic")

This change allows PyCharm to detect the Django structure properly.

Attachments:

image

Test:

Tested with PyCharm Professional Build #PY-241.18034.82, built on June 24, 2024

This problem has also occured for older versions of PyCharm.

urzbs avatar Jul 22 '24 06:07 urzbs