How to correctly set paths to static files and templates in settings.py? Did I put the templates folder there?

/var/www/myproject ├── static_content │ └── static │ ├── img │ ├── css │ ├── js │ ├── templates │ │ ├── main.html │ │ ├── app1 │ │ │ ├── template1.html │ │ │ └── template2.html │ │ └── app2 │ │ └── template1.html │ └── media │ └── img ├── src │ └── myproject │ ├── manage.py │ └── myproject │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── logs └── env ├── bin │ ├── activate │ ├── activate.csh │ ├── activate.fish │ ├── django-admin │ ├── django-admin.py │ ├── easy_install │ ├── easy_install-3.4 │ ├── pip │ ├── pip3 │ ├── pip3.4 │ ├── python -> python3.4 │ ├── python3 -> python3.4 │ └── ... ├── include ├── lib └── docs 

settings.py:

 """ Django settings for firstapp project. Generated by 'django-admin startproject' using Django 1.8.3. For more information on this file, see https://docs.djangoproject.com/en/1.8/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.8/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '...' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app1', 'app2', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', ) ROOT_URLCONF = 'myproject.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ '/var/www/myproject/static_content/static/templates', '/var/www/myproject/static_content/static/templates/app1', '/var/www/myproject/static_content/static/templates/app2', ], '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', ], }, }, ] WSGI_APPLICATION = 'myproject.wsgi.application' # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'db', 'USER': 'user', 'PASSWORD': 'pass', 'HOST': '127.0.0.1', 'PORT': '5432', } } # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'ru-RU' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = os.path.join(BASE_DIR,'static_content/') #STATICFILES_DIRS = ( # ('static', os.path.join(BASE_DIR, "static")), #) 

    1 answer 1

    You have incorrectly defined BASE_DIR, from your code it will point to /var/www/myproject/src/myproject , if you need to point to /var/www/myproject , then you should write something like this:

     BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) 

    in the STATIC_URL setting, only the URL for the browser is specified, to specify the folder, use the STATICFILES_DIRS setting, for your case it will be like this:

     STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static_content', 'static'), ) 

    The templates folder in the static folder is not needed, it is better to place it in the project root (then you can just specify the path), or in the src folder. Accordingly, you need to change the setting to the template folder:

     TEMPLATES = [{ ... 'DIRS': [ os.path.join(BASE_DIR, 'templates') ] ... }]