Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm does not resolve templates nor template tags nor statics in Django project

Tags:

django

pycharm

PyCharm does not find templates, nor template tags, nor static files in my Django project even though the project itself is set up right and working.

I am using Django 1.6.2 with this layout:

proj
  .devtmp
  manage.py
  proj
    settings.py
    app1
      templatetags
  app2
    templates
    static

and with settings like these:

from os.path import join, dirname, pardir, abspath

PROJECT_ROOT = abspath(join(dirname(__file__), pardir))
DEV_TMP_DIR = join(PROJECT_ROOT, pardir, '.devtmp')

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

TEMPLATE_DIRS = (
    join(PROJECT_ROOT, 'templates'),
)

MEDIA_ROOT = join(DEV_TMP_DIR, 'media')
MEDIA_URL = '/media/'

STATIC_ROOT = join(DEV_TMP_DIR, 'static')
STATIC_URL = '/static/'

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
    ...
    'proj'
    'proj.app1'
    'app2'
)

Update:

In the IDE preferences, I have configured paths to the project root, settings.py and manage.py. In addition, I have configured the project interpreter (I am running the runserver from the IDE right now with no problems).

like image 428
zahory Avatar asked Apr 09 '14 19:04

zahory


1 Answers

Please try this - it works for me for templates:

  • set templates directories in Python Template Languages -> Template directories
  • in Project Structure mark your apps as Source Folders

EDIT :
After a project structure reorganization I had problem with static files again. Setting destination of setting.py file in Django Support -> Settings resolved the issue.

like image 73
glowka Avatar answered Nov 03 '22 10:11

glowka