Django的一些css不能在生产中工作



我有一个django应用程序。在生产中,我运行collectstatic,除了一小块css之外都很好。这个css是一个问号,在悬停时显示一些关于应用功能的提示。这也可能是nginx配置问题。但是,这段css不能正常工作。

html

<div class="help-tip">
<p> 
some text
</p>
</div>                               

css

/*-------------------------
Inline help tip
--------------------------*/
.help-tip-wrapper{
padding-top: 15px;
padding-left: 5px;
}
.help-tip{
text-align: center;
background-color: #BCDBEA;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
}
.help-tip:before{
content:'?';
font-weight: bold;
color:#fff;
}
.help-tip:hover p{
display:block;
-webkit-animation: fadeIn 0.3s ease-in-out;
animation: fadeIn 0.3s ease-in-out;
}
.help-tip p{
display: none;
background-color: #1E2021;
padding: 20px;
width: 300px;
border-radius: 3px;
right: -4px;
color: #FFF;
font-weight: normal;
font-size: 10px;
z-index: 100;
line-height: 1.4;
position: relative;
}
.help-tip p:before{
content: '';
width:0;
height: 0;
border:6px solid transparent;
border-bottom-color:#1E2021;
right:10px;
top:-12px;
}
.help-tip p:after{
width:100%;
height:40px;
content:'';
top:-40px;
left:0;
}

settings.py

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

所有css都运行良好,除了这个

您的settings.py文件错误。

应该是这样的

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

您现在还必须更新您的nginxapach2服务器与上述更改'staticfiles'

当你运行collectstatic命令时,它现在将你的包保存在staticfiles目录中,当你运行DEBUG=False命令时,它将被服务。如果您的debug=True,那么它将从static文件夹

服务器

您没有使用"collectstatic"的url映射。在你的设置中,使用这种映射。(除了关键字(变量名))

STATIC_URL = '/static/'
STATICFILES_DIRS=[BASE_DIR / 'static']
STATIC_ROOT= BASE_DIR / 'staticfiles'

之后,运行'collectstatic'。在生产环境中,您将在这个特定的url映射文件中获得所有的css。

最新更新