将Django React应用程序部署到Heroku:迁移错误?:( staticfiles.w004)目录'/app/static'在staticfiles_dirs设置中不存在
我部署的网站现在只是显示了我的CSS或数据的Django Rest框架页面()
我认为这与迁移有关,因为在运行 Heroku Run Python Manage.py Migrate
i之后获取以下错误:
WARNINGS:
?: (staticfiles.W004) The directory '/app/static' in the STATICFILES_DIRS setting does not exist.
是我的设置
from pathlib import Path
import dotenv
import dj_database_url
import os
from decouple import config
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dotenv_file = os.path.join(BASE_DIR, ".env")
if os.path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['localhost', '127.0.0.1:8000', 'ever-actor.herokuapp', ]
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000']
CORS_ORIGIN_WHITELIST = [
'http://localhost:8000',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'api.apps.ApiConfig',
'rest_framework',
'corsheaders',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
ROOT_URLCONF = 'ever_actor.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# BASE_DIR / 'ever-react/build'
os.path.join(BASE_DIR, 'build'),
],
'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 = 'ever_actor.wsgi.application'
# Database
DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CORS_ALLOW_ALL_ORIGINS = True
import django_heroku
django_heroku.settings(locals())
#https://github.com/jazzband/dj-database-url/issues/107
del DATABASES['default']['OPTIONS']['sslmode']
。
Project
|
+--api
|. |
|. +--migrations
|. |. |
|. |. +__init__.py
|. |. +0001_initial.py
|. |
|. +--__init__.py
|. +--admin.py
|. +--apps.py
|. +--models.py
| +--serializers.py
|. +--tests.py
|. +--urls.py
|. +--views.py
|
+--ever-actor
|. |
|. +--__init__.py
|. +--asgi.py
|. +--settings.py
| +--urls.py
| +--wsgi.py
|
+--public (contains index.html)
+--src (contains react components. works on local host)
+--static
+--staticfiles
+--.env
+--db.sqlite3
+--manage.py
+--package-loc.json
+--package.json
+--Pipfile.lock
+--Procfile
+--requirements.txt
这 我真的不知道该如何做到这一点,而不会破坏任何东西(例如,我有两个URL.PY)。还是我的db.sqlite3需要在其他地方?我设置了我的数据库= sqlite:///db.sqlite3,并在Heroku上使用postgressql。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上是在告诉您在项目中制作一个名为static的目录
it's literally telling you to make a directory called static in your project