【问题标题】:Django - Static files not found on ubuntuDjango - 在 ubuntu 上找不到静态文件
【发布时间】:2019-11-29 10:36:57
【问题描述】:

我目前坚持在 lubuntu 上使用 django 处理静态文件,不断收到错误 404,找不到文件。

我已经尝试了多种可能性,我在谷歌上搜索过,但在我的情况下都没有。

我的静态文件位于我的主项目文件夹中的静态文件夹下。

settings.py

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
STATIC_DIR = os.path.join(BASE_DIR,'static')

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'first_app',
]

STATIC_URL = '/static/'
STATICFILES_DIR = [
    STATIC_DIR,
]

你能给我建议在 ubuntu 上处理静态文件的最糟糕的方法是什么,或者如果你在我的情况下看到任何解决方案?

【问题讨论】:

  • 您是否已将您的 peoject 作为 apache 部署到服务器中?
  • 您有STATIC_ROOT 设置吗?你跑collectstatic了吗?
  • 我认为不是。你能告诉我怎么做吗?
  • 我推荐阅读documentation,它相当全面

标签: python django python-3.x ubuntu django-staticfiles


【解决方案1】:

请按照本教程进行操作,Deploying Your Application (Option #1) - Deploy to a Linux Server

它完成了将您的应用成功部署到 ubuntu 服务器的所有步骤。

【讨论】:

    猜你喜欢
    • 2021-08-27
    • 2014-11-10
    • 2011-08-26
    • 2020-06-22
    • 2021-08-16
    • 2020-06-20
    • 2019-06-24
    相关资源
    最近更新 更多