cookiecutter-django
cookiecutter-django copied to clipboard
[BUG] PyCharm Integration with django-cookiecutter
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:
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.
That's a weird one. PR to fix welcome.
Out of curiosity, does it work if you modify the installed apps with .append() or with INSTALLED_APPS += [...]? I'm asking as we do that for other apps:
https://github.com/cookiecutter/cookiecutter-django/blob/41b50bcb7d8a50ef71dd19adc4759d99ad7b75a9/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/local.py#L62
https://github.com/cookiecutter/cookiecutter-django/blob/41b50bcb7d8a50ef71dd19adc4759d99ad7b75a9/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/local.py#L105
Wondering if that would mess things up or if it's supported?
PS: not suitable for whitenoise as it needs to be before staticfiles, it's more of general question.
INSTALLED_APPS += ["whitenoise.runserver_nostatic"] works too, but then its not on top of the list.
Not sure if it matters.
Yes I think it matters for whitenoise, as I said before, the order is important for this app, so your suggestion is better
Did you fill in a bug report by jetbrains?