我正在创建一个项目,我想部署在Heroku上。我们正在使用Django,并希望保持我们对Heroku的静力学,因为它是一个小应用程序。
我遇到的问题是,当Heroku运行python manage.py collectstatic --noinput时,我会遇到一个错误,说明我没有设置STATIC_ROOT。我的文件结构如下:
├── htmlcov
├── mysite
│ ├── settings.py
│ ├── wsgi.py
│ ├── urls.py
│ └── random.py
│
├── staticfiles
├── tweetmood
│ ├── migrations
│ └── tests
│
├── Procfile
├── runtime.txt
└── manage.py我的设置文件是
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 2.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'MY_SUPER_SECRET_KEY'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['0.0.0.0', 'localhost', 'https://my-project-name.herokuapp.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tweetmood',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/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/2.1/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.9/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Configure Django App for Heroku.
django_heroku.settings(locals())Procfile:
web: gunicorn mysite.wsgi —-log-file--在本地,heroku local和heroku local web都工作得很好。但是,即使python manage.py collectstatic --noinput运行,每次也会创建更多的文件。然而,每当我试图推到Heroku时,我都会得到以下错误消息
raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
****** Collectstatic environment variables:ttps://devcenter.heroku.com/articles/django-assets然后打印一组不包括BASE_DIR、STATIC_ROOT或STATIC_URL的环境变量。我怀疑这是我的问题的根本原因,但我不知道如何解决它。
我正在寻找一种方式来增加静力学,以便我可以部署和仍然有这些资源可供我使用。
发布于 2019-05-14 16:26:30
原来,当我推到Heroku时,我推错了分支,而在本地的正确分支上,为了将正确的分支推到heroku远程,您必须使用git push heroku yourbranch:master。
当我通过命令行访问heroku之后,我终于发现了这一点,并查看了我的代码,发现了其中的区别。确保使用正确的分支。
发布于 2022-03-03 12:10:27
在我的例子中,问题是在执行git push heroku之前,我并没有实际地对settings.py进行更改。
https://stackoverflow.com/questions/54327586
复制相似问题