django - django 2.0 中的错误 404 静态文件

标签 django python-3.x django-templates

我正在尝试在 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

最佳答案

试试这个:

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

关于django - django 2.0 中的错误 404 静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48727193/

相关文章:

python - 在 Django/Django Rest 中添加两因素身份验证

python - 在celery.py中导入Django App函数

python - numpy 中连续整数的总和不正确

html - 将值从 Django View 传递到 AngularJS 插入的模板

python - 如何在自定义模板标签中传递 url 标签?

python - 给 reportlab.lib.utils.ImageReader 一个字节

python - 使用 Paramiko 进行 DSA key 转发?

python-3.x - python 请求库在亚马逊 aws 中不起作用

python - 基于 User-Agent 更改 Django 模板

python - DRF APITestCase 不将 `multipart` 与其他参数一起使用