zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    mac重启nginx时报nginx.pid不存在的解决办法
    js 正则表达式
    js 闭包
    js yarn
    js npm
    vue3 vite
    node 错误处理
    node fs
    linux包管理工具使用和区别(转)
    MySQL数据库学习----理论基础
  • 原文地址:https://www.cnblogs.com/lizm166/p/9414156.html
Copyright © 2011-2022 走看看