Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django CAN find my static files, Pycharm CANNOT resolve them

I do not think this is a duplicate. I have looked at a lot of answers to similar problems.

Please note: This runs perfectly fine and django finds all static files.

UPDATE: It looks like this is a PyCharm bug. If I move static into my app directory, the PyCharm can resolve it. But, I have this static in the main src dir because multiple apps will be using the CSS. Right now it runs and Django has no problem with this. I am thiking this is a PyCharm bug.

PyCharm is set up, and everything else seems to work as far as the Django project goodies that Pycharm offers.

Pycharm cannot resolve, whch means that I cannot use auto complete, and it is annoying. If I hit ctrl-space the only directory that pops up is admin. This means that PyCharm is completely ignoring my static directory.

I have also tried making it a templates directory and a resourse director. No luck there either.

{% load static %} <!-- {% load staticfiles %} -->
...
<link rel="stylesheet" href="{% static ''%}">
<link rel="stylesheet" href="{% static 'css/skeleton.css' %}">
<link rel="stylesheet" href="{% static 'css/custom.css' %}">
...

The code above works fine. PyCharm does not find the urls though.

INSTALLED_APPS = [
    'django.contrib.staticfiles',

    # admin specific
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.messages',
    'django.contrib.sessions',
]
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

STATIC_URL = '/static/'

like image 362
Michael Bruce Avatar asked Feb 10 '17 14:02

Michael Bruce


2 Answers

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

like image 174
Mohammad Mahjoub Avatar answered Oct 14 '22 03:10

Mohammad Mahjoub


In some situation this way can work:

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

PyCharm static autocomplete

like image 28
trianglesis Avatar answered Oct 14 '22 04:10

trianglesis