Blogger Information
Blog 75
fans 0
comment 0
visits 54659
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈python之Django怎么使用本地css/js文件
聆听的博客
Original
1044 people have browsed it

刚接触Django框架时,往往好多小伙伴想做出很炫的页面,梦想总是好的,但是一下手,感觉css特效都不知道怎么插进去,js也不会,这可咋整,别担心,其实很简单,小猿圈今天带大家学习一下Django下使用本地css和js。

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

我的文件夹层级

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

实例

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文件中通过以下方式导入:

实例

<!--引入本地css & js-->

<link rel="stylesheet" href="../static/style/app.css" />

<script type="text/javascript" src="../static/js/app.js"></script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

这样就可以为你们梦想的页面而努力,磨毛不误砍柴工,先把准备做好,然后安心的把代码敲好,这样才能做出优美功能强大的页面,这个知识点虽然小,但是很实用,刚接触Django框架的朋友们都会用到,感觉不错的朋友们,可以关注一下小猿圈官网

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!