码迷,mamicode.com
首页 > Web开发 > 详细

Django项目中引用js,css文件的可行方法

时间:2018-03-30 15:17:11      阅读:820      评论:0      收藏:0      [点我收藏+]

标签:win   pre   name   url   type   asc   导入   log   war   

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

第二,在项目同名的app中settings文件末尾添加以下内容:

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 rel="stylesheet" href="../static/style/helloform.css" />
<script type="text/javascript" src="../static/javascript/helloform.js"></script>

不需要修改urls.py文件

这样即可引用js,css等文件

Django项目中引用js,css文件的可行方法

标签:win   pre   name   url   type   asc   导入   log   war   

原文地址:https://www.cnblogs.com/JoinAJR8194/p/8676207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!