官方文档的形式:https://docs.djangoproject.com/en/3.1/howto/static-files/,这个没弄懂。
今天终于找到一个可以用的,记录下,在manager.py同层级下创建static文件夹, 里面放上css , js, image等文件或者文件夹
我的文件夹层级
![](https://img.haomeiwen.com/i16430024/2adec90cc1e857d9.jpg)
然后很简单,只需在settings.py中进行设置就行, 在末尾添加以下代码
import os
STATIC_URL = '/static/'
HERE = os.path.dirname(os.path.abspath(__file__))
HERE = os.path.join(HERE, '../')
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(HERE, 'static/'),
)
在需要使用的html文件中通过以下方式导入
<link href="../static/css/css.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../static/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.SuperSlide.2.1.1.js"></script>
网友评论