[Fixed]-Django CAN find my static files, Pycharm CANNOT resolve them

11👍

Here is the key to solving the problem: Pycharm needs to know where your settings files that you’re currently using is located. See the picture.

enter image description here

Also make sure that you have everything setup in your settings file correctly. See the picture.

enter image description here

2👍

In some situation this way can work:

<link href="{{ STATIC_URL }}" rel="stylesheet" type="text/css">

PyCharm static autocomplete

1👍

If you have setup everything correctly according to Django doc at:
https://docs.djangoproject.com/en/3.1/howto/static-files/

Then you can try to explicitly set your static folders to help the IDE like:

STATICFILES_DIRS = (
    BASE_DIR / "app1/static",
    BASE_DIR / "app2/static",
)

this works for me many times. IntelliJ just could not automatically find my app’s static.

0👍

PyCharm recognises my static files for a configured settings.STATIC_ROOT as below

STATIC_URL = '/assets/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

0👍

Try loading your staticfiles:

{% load staticfiles %}

And setting your link as:

<link rel="stylesheet" type="text/css" href="{% static "css/default.css" %}">
👤Josh

0👍

I used:

  1. STATIC_ROOT = os.path.join(BASE_DIR, "static_deployment")

  2. python manage.py collectstatic command

So I did what needs to be done to go from development to deployment configuration.

pyCharm now works fine and can see static files

Yes it is not the best solution if you change static files a lot but can help developing with pyCharm and Django…

👤Petr

-2👍

Check in settins.py

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'your_app/static/')
]

and add

STATIC_ROOT = os.path.join(BASE_DIR, '/static/')

Pycharm use this settings.

Leave a comment