簡體   English   中英

static 文件目錄未找到(heroku)

[英]static file directory not found (heroku)

我正在使用 Django 2.2 創建一個站點。 但是當我嘗試運行git push heroku master時出現錯誤。 我嘗試了所有的 stackoverflow 答案,但沒有任何效果。 這是我的目錄:

├───.idea
│   └───inspectionProfiles
├───.vscode
├───CheemsCode_Site
│   └───__pycache__
└───homepage
    ├───migrations
    │   └───__pycache__
    ├───static
    │   ├───css
    │   ├───img
    │   │   ├───portfolio
    │   │   ├───team
    │   │   └───testimonials
    │   ├───js
    │   └───vendor
    │       ├───bootstrap
    │       │   ├───css
    │       │   └───js
    │       ├───bootstrap-icons
    │       │   └───fonts
    │       ├───boxicons
    │       │   ├───css
    │       │   └───fonts
    │       ├───glightbox
    │       │   ├───css
    │       │   └───js
    │       ├───isotope-layout
    │       ├───php-email-form
    │       ├───purecounter
    │       └───swiper
    ├───templates
    └───__pycache__

這是我的settings.py:

"""


# Application definition

INSTALLED_APPS = [
    'homepage',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',  # new!
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',  # new!
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'CheemsCode_Site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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 = 'CheemsCode_Site.wsgi.application'


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')  # new!
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

這是錯誤:

(CheemsCode-hO4sBLUa) (CheemsCode) E:\Projects(django)\CheemsCode\CheemsCode_Site>git push heroku master
Enumerating objects: 535, done.
Counting objects: 100% (535/535), done.
Delta compression using up to 8 threads
Compressing objects: 100% (492/492), done.
Writing objects: 100% (535/535), 8.71 MiB | 419.00 KiB/s, done.
Total 535 (delta 255), reused 132 (delta 33), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Python app detected
remote: -----> Installing python-3.9.4
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing dependencies with Pipenv 2020.11.15
remote:        Installing dependencies from Pipfile.lock (849d40)...
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "/tmp/build_dda2808f/manage.py", line 15, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 375, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 316, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 353, in execute   
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 105, in collect
remote:            for path, storage in finder.list(self.ignore_patterns):
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/finders.py", line 125, in list
remote:            for path in utils.get_files(storage, ignore_patterns):
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
remote:            directories, files = storage.listdir(location)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 313, in listdir     
remote:            for entry in os.listdir(path):
remote:        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_dda2808f/static'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to cheemscode.
remote:
To https://git.heroku.com/cheemscode.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cheemscode.git'

這是我運行python manage.py collectstatic時的 output :

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\core\management\base.py", line 364, in execute 
    output = self.handle(*args, **options)
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 188, in handle
    collected = self.collect()
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 105, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\contrib\staticfiles\finders.py", line 131, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\contrib\staticfiles\utils.py", line 23, in get_files
    directories, files = storage.listdir(location)
  File "C:\Users\Asus\.virtualenvs\CheemsCode-hO4sBLUa\lib\site-packages\django\core\files\storage.py", line 315, in listdir   
    for entry in os.scandir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'E:\\Projects(django)\\CheemsCode\\CheemsCode_Site\\static'

我該如何解決這個問題? 我搜索了谷歌和 SO,但對我沒有任何幫助。

好的,我通過將STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]更改為STATICFILES_DIRS = [os.path.join(BASE_DIR, 'homepage/static'), ] ..

希望它會工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM