0

所以我正在运行命令

python manage.py collectstatic

我收到一个错误,我很确定这是因为我的 settings.py 中有一些设置。首先我会附上一张图片,这样每个人都可以看到我的文档树,然后是错误本身。

知道我做错了什么吗?谢谢你。

图片: 带有文件和设置树的图像

我的设置.py

# on the top
import os

# on the bottom
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.normpath(os.path.join(BASE_DIR, 'staticfiles'))
STATIC_URL = '/static/'


MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

错误如下:

(env) PS C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project> python manage.py collectstatic
Traceback (most recent call last):
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\manage.py", line 22, in <module>
    main()
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 194, in handle 
    collected = self.collect()
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 109, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\contrib\staticfiles\finders.py", line 130, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\contrib\staticfiles\utils.py", line 23, in get_files
    directories, files = storage.listdir(location)
  File "C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project\env\lib\site-packages\django\core\files\storage.py", line 316, in listdir
    for entry in os.scandir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\lenil\\Documents\\Development\\Personal Projects\\the-journey\\thejourney_project\\thejourney_project\\static'     
(env) PS C:\Users\lenil\Documents\Development\Personal Projects\the-journey\thejourney_project> 

非常感谢你的帮助!

4

2 回答 2

0

您附加的项目结构图像未显示static或的目录staticfiles。您需要将这些目录向上移动,或更改映射到这些目录的路径。

于 2021-01-27T16:16:30.653 回答
0

我尝试重新部署,这次使用了这些设置。它对我有用。

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATIC_DIRS = (
    os.path.join(BASE_DIR, 'projects/static'),
)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

我还必须将 Procfile 更改为此

web: python manage.py runserver 0.0.0.0:$PORT

整个步骤:

First make sure you have requirements.txt and Procfile
In Procfile, the contents were like this
web: python manage.py runserver 0.0.0.0:$PORT
And run python manage.py collectstatic just to make sure no errors from collectstatic
Then these commands in cmd
heroku login
Then login from browser
git init
heroku git:remote -a app_name
git add .
git commit -am "first commit"
git push heroku main         -------------– or masterher
heroku run python manage.py migrate
heroku open
于 2021-01-27T16:38:08.607 回答