尝试部署django时出现静态文件问题

问题描述 投票:0回答:1

我正在尝试按照this教程部署Django,但是收到错误。当教程说要运行python manage.py collectstatic时,我没有按照建议运行而没有进一步的提示,而是运行,我得到以下内容:

/home/elections/venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)

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

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

Type 'yes' to continue, or 'no' to cancel: yes

我输入了Yes并收到以下错误:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/elections/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
    collected = self.collect()
  File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
    if self.storage.exists(prefixed_path):
  File "/home/elections/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 392, in exists
    return os.path.exists(self.path(name))
  File "/home/elections/venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 50, in path
    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.

什么可能使这种情况与教程不同,我该如何解决这个错误?

python django ubuntu
1个回答
1
投票

如前所述,您需要在STATIC_ROOT中定义settings.py变量,以使collectstatic工作。

collectstatic将收集静态文件以进行部署的目录的绝对路径。示例:“/ var / www./example.com/static/”

您可能也想定义STATICFILES_DIRS


您发布的教程中的nginx.conf期望从/home/boards/staticfiles/提供您收集的静态文件。由于本教程将所有内容部署在托管数据库(postgres),Web服务器(nginx)和应用程序(django)的单个整体服务器上,因此您可以按如下方式进行设置:

STATIC_ROOT = '/home/boards/staticfiles/'
© www.soinside.com 2019 - 2024. All rights reserved.