温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

通过Django使用本地css/js文件的示例

发布时间:2021-02-01 14:09:26 来源:亿速云 阅读:235 作者:小新 栏目:开发技术

这篇文章主要介绍通过Django使用本地css/js文件的示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在manager.py同层级下创建static文件夹, 里面放上css , js, image等文件或者文件夹

我的文件夹tree:

➜ FileService git:(master) ✗ tree
.
├── 2kill_port.sh
├── FileService
│  ├── __init__.py
│  ├── __pycache__
│  │  ├── __init__.cpython-37.pyc
│  │  ├── settings.cpython-37.pyc
│  │  ├── urls.cpython-37.pyc
│  │  └── wsgi.cpython-37.pyc
│  ├── settings.py
│  ├── urls.py
│  └── wsgi.py
├── db.sqlite3
├── en_bg.jpg
├── fileoperation
│  ├── __init__.py
│  ├── __pycache__
│  │  ├── __init__.cpython-37.pyc
│  │  ├── admin.cpython-37.pyc
│  │  ├── models.cpython-37.pyc
│  │  └── views.cpython-37.pyc
│  ├── admin.py
│  ├── apps.py
│  ├── migrations
│  │  ├── __init__.py
│  │  └── __pycache__
│  │    └── __init__.cpython-37.pyc
│  ├── models.py
│  ├── templates
│  │  ├── bg_homg.html
│  │  └── home.html
│  └── views.py
├── files
│  ├── 11.log
│  ├── 22.log
│  ├── 44.log
│  ├── th.jpeg
│  ├── �\217�\225快�\205�\ 2020-01-08\ �\213�\215\2101.50.03.png
│  └── �\235�\231��\212��\224\200�\207��\201.pdf
├── kill_port.sh
├── manage.py
└── static
  ├── images
  │  └── en_bg.jpg
  └── style
    └── style.css

然后只需在FileService/settings.py中进行设置就行, 在末尾添加以下代码

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

最后只需要在使用的html文件中通过以下方式导入:

<head>
  <link rel="stylesheet" type="text/css" href="../static/style/style.css" rel="external nofollow" />
  <meta charset="UTF-8">
  <title>文件传输</title>
</head>

以上是“通过Django使用本地css/js文件的示例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI