gpt4 book ai didi

django - Python manage.py collectstatic 类型错误 : an integer is required (got type str)

转载 作者:行者123 更新时间:2023-12-01 19:33:10 24 4
gpt4 key购买 nike

我正在使用 Django 2.2 版。当我运行命令时python manage.py collectstatic

我在 bash 终端上得到以下日志。

You have requested to collect static files at the destination
location as specified in your settings:

/home/djapp/poorface/staticfiles

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
collected = self.collect()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 353, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 288, in _save
os.chmod(full_path, self.file_permissions_mode)
TypeError: an integer is required (got type str)

我将静态文件的权限更改为 -rwxrwxrwx 。然后输出也没有变化。

manage.py 看起来像

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Poorface.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

最佳答案

这是一个 hack - 不是一个正确的修复!

我在 OSX 和 Ubuntu 上都遇到过这个问题。似乎某些包最终以字符串形式获得文件权限,而大多数是整数。

我破解了 django 来解决这个问题,并确定了导致问​​题的包 - django-filebrowser - 可能最好不要破解 django 但如果绝望,这里是 core/files/storage.py 行 289::的更改:

    if self.file_permissions_mode is not None:

if type(self.file_permissions_mode) == type("duck"):
print(full_path, self.file_permissions_mode, type(self.file_permissions_mode))
self.file_permissions_mode = int(self.file_permissions_mode)
os.chmod(full_path, self.file_permissions_mode)

此报告::

  /home/django/teamup/shared_static/filebrowser/css/filebrowser.css 0644 <class 'str'>

我尝试在 virtualenv 中更改 filebrowser 的文件权限并重新运行,但这并没有解决问题,所以我已经进行了修改。

关于django - Python manage.py collectstatic 类型错误 : an integer is required (got type str),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55538153/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com