gpt4 book ai didi

python - Django 1.8 CSS 加载不完全

转载 作者:行者123 更新时间:2023-11-28 05:24:48 25 4
gpt4 key购买 nike

我几乎查找了所有关于 Django CSS、JS、图像文件未加载的解决方案。但是,我认为我的元素有所不同。

我想制作一个 RWD 网站,但它在小屏幕上不起作用。没有菜单,没有改变模板。

我可以看到 CSS 有效,但不完全有效。 image description here

尽我所能找到解决方案。我混淆了静态文件和路径,什么是正确的级别。

Here is my project path Image

我尝试了很多方法,我删除了那些没有真正涉及的方法以保持代码干净,因为有人可以帮助我。

设置.py

    TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templated-EX').replace('\\', '/')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

...

STATIC_URL = '/static/'

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

STATIC_DIRS = [
('css',os.path.join(STATIC_ROOT,'css').replace('\\','/') ),
('js',os.path.join(STATIC_ROOT,'js').replace('\\','/') ),
('images',os.path.join(STATIC_ROOT,'images').replace('\\','/') ),
# ('upload',os.path.join(STATIC_ROOT,'upload').replace('\\','/') ),
]
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

index.html

{% load staticfiles %}

<!DOCTYPE HTML>
<!--
Ex Machina by TEMPLATED
templated.co @templatedco
Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
-->
<html>
<head>
<title>Ex Machina by TEMPLATED</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:700italic,400,300,700' rel='stylesheet' type='text/css'>
<!--[if lte IE 8]><script src="{% static "js/html5shiv.js" %}"></script><![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/static/js/skel.min.js"></script>
<script src="/static/js/skel-panels.min.js"></script>
<script src="/static/js/init.js"></script>

<link rel="stylesheet" href="/static/css/skel-noscript.css" />
<link rel="stylesheet" href="/static/css/style.css"/>
<link rel="stylesheet" href="/static/css/style-desktop.css"/>

我还尝试向 urls.py 添加一些内容。也无法改进。

我是 Django 的新手,一定丢失了一些重要的东西。我卡了几天。


更新0810

好的,伙计们,

我想我比以前更清楚了。我尝试下载另一个模板并构建一个新元素。再次执行程序。

新元素没问题!所以程序是正确的。

我检查了我提到的原始模板,它与我的有点不同。不同的是 html 和 CSS。

index.html 中的原始 CSS

<noscript>
<link rel="stylesheet" href="{% static "css/skel-noscript.css" %}"/>
<link rel="stylesheet" href="{% static "css/style.css" %}"/>
<link rel="stylesheet" href="{% static "css/style-desktop.css" %}"/>
</noscript>

如果您使用 <noscript></noscript> 则它不起作用在 html 中。也许我删除了<noscript></noscript>因为 Django 不能用它运行。

最佳答案

尝试像这样更改 html 中的 href:

<link rel="stylesheet" href="{{STATIC_URL}}css/skel-noscript.css" />

如果这不起作用,请告诉我。

编辑:您的 BASE_DIR 设置是什么?您可以尝试以下设置吗?

# Static Files
STATIC_ROOT = join(os.path.dirname(BASE_DIR), 'staticfiles')
STATICFILES_DIRS = [join(os.path.dirname(BASE_DIR), 'static'), ]
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

关于python - Django 1.8 CSS 加载不完全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com