1

I'm using Django with Pycharm.

I started to use Pycharm Professional today, and Pycharm doesn't recognize my bootstrap.min.css file.

<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
Errors

I actually have that file in my project folder, but It doesn't appear in Pycharm file tree.
my project folder
pycharm file tree

Of course, I've set the static_dir, staticfiles_dirs, and static_root.
django static settings

This never happened in Pycharm educational version.

thank you

Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31
Jason Kim
  • 143
  • 1
  • 9
  • 2
    I think the easiest way to solve this would be to let Pycharm tell you where it thinks the static dir is. Then press the key combination for auto complete. It should show you a directory/list of directories where it thinks the folder is. – wrabbit Feb 12 '18 at 06:49
  • [Pycharm Entry](https://www.jetbrains.com/help/pycharm/auto-completing-code.html?keymap=secondary_mac_os_x) – wrabbit Feb 12 '18 at 06:52
  • Make sure {% load staticfiles %} is at the top of your template files – ja408 Feb 22 '18 at 07:44
  • This answered it for me: https://stackoverflow.com/questions/34679755/pycharm-unresolved-library-staticfiles – Oliver Weisfeld Nov 04 '22 at 11:03

4 Answers4

3

I solved the problem. You need to change the Pycharm preference.

Preferences > Languages & Frameworks > Python Template Languages > Template language: Django

pic

iBug
  • 35,554
  • 7
  • 89
  • 134
Jason Kim
  • 143
  • 1
  • 9
  • While we understand that you may be a little excited, please don't use F-words as it may sound offensive to others. – iBug Feb 25 '18 at 14:07
  • You can link the picture and someone will edit them in. – Welz Feb 25 '18 at 14:08
2

settings.py remove STATIC_ROOT, replace the others like so:

STATIC_URL = '/static/'

STATICFILES_DIRS = [

    os.path.join(BASE_DIR, 'static'),
]

At the top of your template, before any HTML {% load static %}

Skope martin
  • 75
  • 1
  • 8
0
put this code in settings.py
IN WINDOW OS

STATIC_URL = '/static/'
STATIC_ROOT= ''
STATICFILES_DIRS = ('C:/Python27/Scripts/yourprojectname/static/'),


IN UBUNTU

STATIC_URL = '/static/'
STATIC_ROOT= ''
STATICFILES_DIRS = ('/yourprojectfolderpath/static/'),


AND IN TEMPLATE FILE ON THE TOP

{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.min.css" />
Digi Quore
  • 291
  • 1
  • 2
  • 18
0

in settings.py

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

and then add >>>>>>>>>>>>>>>STATICFILES_DIRS =['PUT THE PATH TO YOUR STATIC FILE HERE(YOUR PROJECT FOLDER WHICH contains IT)/static/']

like so
 STATICFILES_DIRS = [
        "qinasmartmap/static/",
        "qinasmartmap/qinaservics/static/",
    
    ]

then add it to

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [STATIC_DIR, ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

don't forget to {% load static %} in your HTML files

MoShamroukh
  • 785
  • 7
  • 7