【问题标题】:Error 404 static files in django 2.0django 2.0 中的错误 404 静态文件
【发布时间】:2018-07-21 11:38:12
【问题描述】:

我正在尝试在 django 2.0 中找到我的所有静态文件。但是当我只运行服务器时,我得到了 404 错误

这是我的设置代码

STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/example.com/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

还有我的网址代码

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('naturalUser.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

404 错误

[11/Feb/2018 00:45:11] "GET /static/bower_components/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 1869
[11/Feb/2018 00:45:11] "GET /static/internal/css/general.css HTTP/1.1" 404 1797
[11/Feb/2018 00:45:11] "GET /static/internal/css/AdminLTE.min.css HTTP/1.1" 404 1812
[11/Feb/2018 00:45:11] "GET /static/internal/css/skins/all-skins.min.css HTTP/1.1" 404 1833
[11/Feb/2018 00:45:11] "GET /static/internal/js/adminlte.min.js HTTP/1.1" 404 1806
[11/Feb/2018 00:45:11] "GET /static/bower_components/jquery/internal/jquery.min.js HTTP/1.1" 404 1863
[11/Feb/2018 00:45:11] "GET /static/bower_components/bootstrap/internal/js/bootstrap.min.js HTTP/1.1" 404 1890
[11/Feb/2018 00:45:11] "GET /static/bower_components/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 1869
[11/Feb/2018 00:45:11] "GET /static/internal/css/AdminLTE.min.css HTTP/1.1" 404 1812
[11/Feb/2018 00:45:11] "GET /static/internal/css/general.css HTTP/1.1" 404 1797
[11/Feb/2018 00:45:11] "GET /static/internal/css/skins/all-skins.min.css HTTP/1.1" 404 1833
[11/Feb/2018 00:45:11] "GET /static/bower_components/jquery/internal/jquery.min.js HTTP/1.1" 404 1863
[11/Feb/2018 00:45:11] "GET /static/bower_components/bootstrap/internal/js/bootstrap.min.js HTTP/1.1" 404 1890

【问题讨论】:

    标签: django python-3.x django-templates


    【解决方案1】:

    试试这个:

    STATIC_URL = '/static/'
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static")
    ]
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 2019-01-23
      • 2021-02-28
      • 2016-04-08
      • 2021-11-25
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      相关资源
      最近更新 更多