![](/img/trans.png)
[英]Django. settings.py -> STATIC_ROOT/STATICFILES_DIRS
[英]How to fix [Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django
我正在嘗試將項目經理應用程序部署到 heroku。 它正在本地運行。 我正在按照教程https://www.codementor.io/@jamesezechukwu/how-to-deploy-django-app-on-heroku-dtsee04d4部署我的應用程序。 我不知道錯誤在哪里以及如何修復,所以希望您能提供幫助。 NotADirectoryError at /
,說[Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json'
NotADirectoryError at /
[Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json'
這是我的一些后端代碼:
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'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',
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
PROJECT_ROOT = os.path.join(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra lookup directories for collectstatic to find static files
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
# Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
import dj_database_url
prod_db = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(prod_db)
我無法成功鏈接到靜態文件。 這是我的 html 模板代碼的錯誤部分: Error during template rendering
<link
rel="stylesheet"
type="text/css"
href="{% static 'projectManager/style.css' %}"
/>
我的意見.py:
def home(request):
return render(request, 'projectManager/home.html', {'projects': Project.objects.all()})
我的models.py:
class Project(models.Model):
title = models.CharField(max_length=100)
date = models.DateTimeField(auto_now_add=timezone.now())
def __str__(self):
return self.title
[Errno 20] 不是目錄:'/app/myProjectManager/settings.py/staticfiles/staticfiles.json'
罪魁禍首是:
PROJECT_ROOT = os.path.join(os.path.abspath(__file__))
# That means:
# PROJECT_ROOT = '/app/myProjectManager/settings.py/'
# And:
# STATIC_ROOT: '/app/myProjectManager/settings.py/staticfiles/'
# which is incorrect
如果staticfiles
在app
,則將其更改為:
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# That means:
# PROJECT_ROOT: '/app/'
# And:
# STATIC_ROOT: '/app/staticfiles/'
# Which is correct.
您需要根據settings.py
與項目根目錄相比的位置更新PROJECT_ROOT
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.