Python 尝试部署django时出现Staticfile问题

Python 尝试部署django时出现Staticfile问题,python,django,ubuntu,Python,Django,Ubuntu,我试图按照教程部署Django,但遇到了一个错误。当教程要求运行python manage.py collectstatic,而不是像建议的那样在没有进一步提示的情况下运行collectstatic时,我得到以下结果: /home/elections/venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from rele

我试图按照教程部署Django,但遇到了一个错误。当教程要求运行python manage.py collectstatic,而不是像建议的那样在没有进一步提示的情况下运行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.

是什么原因导致这种情况不同于本教程,我如何修复此错误?

如前所述,您需要在settings.py中定义变量才能正常工作

collectstatic将收集的目录的绝对路径 用于部署的静态文件。 示例:/var/www/Example.com/static/

您可能也需要定义

您发布的教程中的希望提供从/home/boards/staticfiles/收集的静态文件。由于本教程将所有内容部署在单个单片服务器上,该服务器承载数据库postgres、web服务器nginx和应用程序django,因此您可以按如下方式进行设置:

STATIC_ROOT = '/home/boards/staticfiles/'

正如它明确指出的,您必须在设置中设置静态根路径。py@SumeetKumar教程中说,这个命令将所有静态资产复制到一个外部目录,NGINX可以在这个目录中为我们提供文件。您知道我应该将STATIC_ROOT设置为什么吗?如果您正在使用nginx进行设置,那么您可能需要检查nginx conf文件并为静态路径添加别名。