Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] PyCharm Integration with django-cookiecutter #5239

Open
urzbs opened this issue Jul 22, 2024 · 4 comments
Open

[BUG] PyCharm Integration with django-cookiecutter #5239

urzbs opened this issue Jul 22, 2024 · 4 comments
Labels

Comments

@urzbs
Copy link

urzbs commented Jul 22, 2024

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 urzbs added the bug label Jul 22, 2024
@browniebroke
Copy link
Member

browniebroke commented Jul 22, 2024

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:

INSTALLED_APPS += ["django_extensions"]

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.

@urzbs
Copy link
Author

urzbs commented Jul 22, 2024

INSTALLED_APPS += ["whitenoise.runserver_nostatic"] works too, but then its not on top of the list.
Not sure if it matters.

@browniebroke
Copy link
Member

Yes I think it matters for whitenoise, as I said before, the order is important for this app, so your suggestion is better

@foarsitter
Copy link
Collaborator

Did you fill in a bug report by jetbrains?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants