Я могу выполнить коллистатический штраф, когда нажимаю на Героку.Проблема в том, что я не знаю, как ссылаться на них, когда они хранятся на сервере.
Например, для моих таблиц стилей я получаю ошибку 404: <link rel="stylesheet" type="text/css" href="/static/bower_components/bootstrap-material-design/dist/css/material.css" />
Это URL в консоли, который вызывает 404: GET https://tixblast-membership.herokuapp.com/static/bower_components/bootstrap-material-design/dist/css/material.css net::ERR_ABORTED 404 (Not Found)
Какая частьиз моих настроек, чтобы я изменил, чтобы убедиться, что я смотрю в нужном месте?Я запустил heroku run python manage.py findstatic --verbosity 2 css/styles.css
, чтобы показать, где он ищет статические файлы, и он вернул: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/static
/app/.heroku/python/lib/python3.7/site-packages/rest_framework/static
Так что мне нужно включить один из вышеперечисленных каталогов в мои настройки?
Я предположилчто после того, как я начал работать с collectstatic, все будет в порядке, вот мои settings.py:
"""
Django settings for thinkster_django_angular_boilerplate project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import django_heroku
PROJECT_DIR = os.path.dirname(__file__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/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 = os.environ.get('DEBUG', True)
TEMPLATE_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',
'rest_framework',
'authentication'
)
MIDDLEWARE_CLASSES = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
)
ROOT_URLCONF = 'thinkster_django_angular_boilerplate.urls'
WSGI_APPLICATION = 'thinkster_django_angular_boilerplate.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
import dj_database_url
DATABASES = {
'default': dj_database_url.config(
default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
)
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR,'static'),
],
'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',
],
},
},
]
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'compressor.finders.CompressorFinder',
)
COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
)
}
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
AUTH_USER_MODEL = 'authentication.Account'
django_heroku.settings(locals())
edit:
Моя таблица стилей:
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/bootstrap/dist/css/bootstrap.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/bootstrap-material-design/dist/css/material.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/bootstrap-material-design/dist/css/ripples.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/ngDialog/css/ngDialog.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'bower_components/ngDialog/css/ngDialog-theme-default.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'lib/snackbarjs/snackbar.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'stylesheets/styles.css' %}" />
edit2:
Структура файла, в которой находится мое приложение, находится в той же папке, что и мои settings.py.Это единственный способ, которым герою это заметит:
└───static
├───bower_components
│ ├───angular
│ ├───angular-cookies
│ ├───angular-route
│ ├───bootstrap
│ │ ├───dist
│ │ │ ├───css
│ │ │ ├───fonts
│ │ │ └───js
│ │ ├───fonts
│ │ ├───grunt
│ │ ├───js
│ │ ├───less
│ │ │ └───mixins
│ │ └───nuget
│ ├───bootstrap-material-design
│ │ ├───dist
│ │ │ ├───css
│ │ │ ├───fonts
│ │ │ └───js
│ │ ├───fonts
│ │ ├───less
│ │ ├───sass
│ │ └───scripts
│ ├───jquery
│ │ ├───dist
│ │ └───src
│ │ ├───ajax
│ │ │ └───var
│ │ ├───attributes
│ │ ├───core
│ │ │ └───var
│ │ ├───css
│ │ │ └───var
│ │ ├───data
│ │ │ └───var
│ │ ├───effects
│ │ ├───event
│ │ ├───exports
│ │ ├───manipulation
│ │ │ └───var
│ │ ├───queue
│ │ ├───sizzle
│ │ │ └───dist
│ │ ├───traversing
│ │ │ └───var
│ │ └───var
│ ├───ngDialog
│ │ ├───css
│ │ └───js
│ └───underscore
├───javascripts
│ └───authentication
│ ├───controllers
│ │ └───New folder
│ └───services
└───lib
└───snackbarjs
edit 3:
Здесь django ищет шаблоны в соответствии с экраном ошибок:
Using engine django:
django.template.loaders.filesystem.Loader: /app/static/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/templates/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/rest_framework/templates/index.html (Source does not exist)