zoukankan      html  css  js  c++  java
  • django添加静态文件

      最近做了一个todolist webapp,需要稍微添加css时候又忘记django的添加方法了,查看了以前的项目才想起来,所以记录一下.

      1.settings.py 将以下代码放到最下面

    STATIC_URL = '/static/'
    
    STATICFILES_DIRS = (  
        os.path.join(BASE_DIR),
    )
    
    STATICFILES_FINDERS = (
        "django.contrib.staticfiles.finders.FileSystemFinder",
        "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    )
    

      2.给html添加静态文件要点

    首行加入,一定要放在首行~

    {% load staticfiles %}   
    

    然后按照jinjia2或者djagno template的语法加上css等静态文件的路径

        <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />

    搞定~  

    欣赏下最近做的todolist工具~

     

     

    源码地址:https://github.com/fankcoder/ShowMeTheCode/tree/master/s24/todo

    欢迎在github上fork我的代码一起优化~

    本文原创欢迎转载,转载请注明原地址:http://www.cnblogs.com/frankcoder/p/5145614.html

  • 相关阅读:
    Eclipse中用两个控制台测试网络通信程序
    c++ primer 11 泛型算法
    c++ primer 10 关联容器
    c++ primer 9 顺序容器
    c++ primer 8 标准IO库
    安装使用
    InfluxDB介绍
    proxy.go
    monitor.go
    balancer.go
  • 原文地址:https://www.cnblogs.com/frankcoder/p/5145614.html
Copyright © 2011-2022 走看看