Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 静态文件不会收集在名为资产的根文件夹中_Python 3.x_Django_Django Templates_Django Staticfiles_Django Settings - Fatal编程技术网

Python 3.x 静态文件不会收集在名为资产的根文件夹中

Python 3.x 静态文件不会收集在名为资产的根文件夹中,python-3.x,django,django-templates,django-staticfiles,django-settings,Python 3.x,Django,Django Templates,Django Staticfiles,Django Settings,GitHub Repo用于与此问题相关的所有文件:- 更新 静态文件未收集到静态根文件夹中 我已经更改了Django框架的基本目录(telusko)的设置,并在index.html中添加了{%load static%},但chrome的控制台显示: GEThttp://127.0.0.1:8000/static/plugins/OwlCarousel2-2.2.1/owl.carousel.css net::ERR_中止404(未找到) setting.py的代码段; sitetravelo包

GitHub Repo用于与此问题相关的所有文件:-

更新 静态文件未收集到静态根文件夹中

我已经更改了Django框架的基本目录(telusko)的设置,并在
index.html
中添加了
{%load static%}
,但chrome的控制台显示:

GEThttp://127.0.0.1:8000/static/plugins/OwlCarousel2-2.2.1/owl.carousel.css
net::ERR_中止404(未找到)
setting.py的代码段
sitetravelo
包含所有HTML、CSS、js文件,我通过cmd
python manage.py collectstatic
为所有静态文件创建了资产

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STATICFILILE_DIRS = [
    os.path.join(BASE_DIR, 'sitetravello')
]

STATIC_ROOT = os.path.join(BASE_DIR,'assets')
index.html
文件代码为:

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Travello</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Travello template project">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="{% static 'styles/bootstrap4/bootstrap.min.css' %}">
<link href="{% static 'plugins/font-awesome-4.7.0/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
CHROME控制台中出现错误:

GEThttp://127.0.0.1:8000/static/plugins/OwlCarousel2-2.2.1/owl.carousel.css
net::ERR_中止404(未找到)

您的
静态根目录
设置为查找名为
资产的文件夹
。确保您的
plugins/OwlCarousel2-2.2.1/owl.carousel.css
位于
assets
命名文件夹中。

能否共享您的目录结构?我们需要查看您的目录结构以进一步帮助您。这类错误通常是由于为静态文件配置了错误的/不同的文件夹造成的…所有文件都位于此处:-…@Daniel@Ralf和我发现我的自定义静态文件没有收集到assets文件夹中不知道为什么,这就是静态文件未在资产中正确收集的问题file@YashDubey运行管理命令
collectstatic
时,应用程序中的
static
目录的内容将收集到
STATICFILES\u DIRS
中提到的目录中。我还注意到您可能有一个打字错误
STATICFILILE\u DIRS
。您可以看到,在更正打字错误后,不会发生任何情况。我的自定义静态文件没有收集到
资产中
,看起来您确实拥有它,并且根据您的设置,它位于正确的位置。我克隆了您的项目,发现
插件/OwlCarousel2-2.2.1/owl.carousel.css
确实从静态加载到浏览器中。如果在浏览器中看不到缓存,请尝试清除缓存,然后重新启动服务器