Django 2.0中的错误404静态文件 [英] Error 404 static files in django 2.0

查看:91
本文介绍了Django 2.0中的错误404静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to locate all my static files in django 2.0. But when i run the server only i got 404 errors

这是我的设置代码

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

推荐答案

尝试一下:

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

这篇关于Django 2.0中的错误404静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆