zoukankan      html  css  js  c++  java
  • Django使用本地css/js文件的基本流程

     在网上看了很多说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�2152101.50.03.png
    │   └── �235�231��212��224200�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" />
        <meta charset="UTF-8">
        <title>文件传输</title>
    
    </head>
    
    
  • 相关阅读:
    Python格式化输出
    每天写点shell脚本 (持续更新)
    linux limits.conf 配置
    ELK 日志分析系统
    开源大数据处理工具
    glusterFS分布式存储部署流程
    glusterFS的部署流程
    parted命令详解
    /proc文件系统
    /proc文件系统(二):/proc/<pid>/stat
  • 原文地址:https://www.cnblogs.com/dylancao/p/12170390.html
Copyright © 2011-2022 走看看