Django静态文件未在生产中加载

时间:2017-09-01 12:13:15

标签: django

我在EC2实例中加载静态文件时总是遇到404错误。我搜索了几个小时,试图实施各种建议但没有任何效果。

enter image description here

以下是我对不同文件的配置:

settings.py

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

HTML

{% extends "base.html" %}
{% load staticfiles %}

{% block extra_head %}
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.12/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.js"></script>
    <script src="{% static "ddv_example/ddv_example_1_10.js" %}"></script>
    <script type="text/javascript">

nginx.conf

location /static/admin {
        alias /usr/local/virtualenvs/mysite/lib/python2.7/site-packages/django/contrib/admin/static/admin;
    }

    location /static/rest_framework {
        alias /usr/local/virtualenvs/mysite/lib/python2.7/site-packages/rest_framework/static/rest_framework;
    }

    location /static {
        alias /usr/local/apps/mysite/src/mysite/mysite/static;
    }


    location /static/ddv_example {
        alias /usr/local/apps/mysite/src/mysite/mysite/static/ddv_example;
    }

关于我错过了什么的任何建议?

1 个答案:

答案 0 :(得分:0)

我错过了重新运行sudo ./server_setup.sh。只有在重新运行脚本时,nginx配置才会生效。