通过 AWS Elastic Beanstalk 部署 Django 应用程序会破坏 CSS 路径



我刚刚通过 Elastic Beanstalk 将我的第一个简单的 Django 1.8.6(以防万一)应用程序部署到 AWS。

一切似乎都在工作;但是,样式没有加载。

以下是模板的代码:

{% load blog_tags %}
{% load staticfiles %}
   <!DOCTYPE html>
   <html>
   <head>
     <title>{% block title %}{% endblock %}</title>
     <link href="{% static "css/blog.css" %}" rel="stylesheet">
   </head>
   <body>
     <div id="content">
       {% block content %}
       {% endblock %}
     </div>
     <div id="sidebar">
       <h2>My blog!</h2>
       <p>This is my blog. I have written {% total_posts %} posts so far.</p>
       <h3>Latest posts</h3>
       {% show_latest_posts 3 %}
     </div>
   </body>
   </html>

这是页面的源代码:

 <!DOCTYPE html>
   <html>
   <head>
     <title>My Blog !!!</title>
     <link href="/static/css/blog.css" rel="stylesheet">
   </head>
   <body>
     <div id="content"> ...

如果我在本地机器上点击链接"/static/css/blog.css",CSS文件就会打开;但是,在Beanstalk上找不到它。

我怀疑这与某些配置有关。知道我可以在哪里解决这个问题吗?

编辑:

这是 .ebextensions/django.config 文件

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: django_by_example_blog/wsgi.py
    StaticFiles: /static/=static/

如果您使用的是 AMI 2,则可以使用这个

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: mysite.wsgi:application
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /static: static
container_commands:
  01_collectstatic:
    command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py collectstatic --noinput"
  02_migrate:
    command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py migrate --noinput"
    leader_only: true

最新更新