【问题标题】:When deploying Django application on cpanel, application does not connect to static files在 cpanel 上部署 Django 应用程序时,应用程序未连接到静态文件
【发布时间】:2021-01-24 01:23:24
【问题描述】:

我正在尝试从 cpanel 部署 django 应用程序。我已经设法部署了站点,除了静态文件部分之外,一切都正常工作,因为我的网站加载时没有任何样式。我的 settings.py 部分如下所示:

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR,'assets'),
]

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

当我在 cpanel 终端命令“python manage.py collectstatic”上运行命令时,它运行良好并复制文件,但是网站加载时没有样式。此外,我的基本 html 看起来像这样(以防我需要在那里更改一些东西,但是在本地服务器上一切运行正常):

{% load static %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>About</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link href="https://fonts.googleapis.com/css?family=Work+Sans:100,200,300,400,700,800" rel="stylesheet">

    <!-- {% static 'website/css/owl.carousel.min.cs' %} -->
    <link rel="stylesheet" href="{% static 'website/css/open-iconic-bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'website/css/animate.css' %}">

【问题讨论】:

  • Django 确实在生产中提供静态文件。
  • 我看过这个文档,但我还是不明白。你能不能把它翻译成人类语言或者只是举一些例子应该如何解决它?
  • 我想我不明白的部分是“配置您的 Web 服务器以在 URL STATIC_URL 下提供 STATIC_ROOT 中的文件。例如,这是使用 Apache 和 mod_wsgi 执行此操作的方法。”跨度>

标签: python django cpanel web-deployment


【解决方案1】:

只是为了回答我自己的问题,我了解到我需要使用 WhiteNoise 库,然后对 settings.py 文件进行一些调整,瞧!一切正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-18
    • 2016-12-23
    • 2019-04-04
    • 2021-07-23
    • 2020-12-17
    • 2022-12-06
    • 2021-03-16
    • 2020-05-17
    相关资源
    最近更新 更多