zoukankan      html  css  js  c++  java
  • Django基础,Day7

    添加css样式文件

    1、首先在app目录下创建static文件夹,如polls/static。django会自动找到放在这里的静态文件。

    AppDirectoriesFinder which looks for a “static” subdirectory in each of the INSTALLED_APPS

    STATICFILES_DIRS:This setting defines the additional locations the staticfiles app will traverse if the FileSystemFinder finder is enabled

    2、创建polls/static/polls/style.css

    Because of how the AppDirectoriesFinder staticfile finder works, you can refer to this static file in Django simply as polls/style.css

    li a {
        color: green;
    }
    

    3、在页面头部中引入css,引入方式  

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

     {% static %} :生成静态资源static file的绝对url路径

    polls/templates/polls/index.html:

    4、刷新首页,可见链接内的文字颜色已变为green

    添加背景图片

    1、添加图片 polls/static/polls/images/background.jpg

    2、添加css样式 polls/static/polls/style.css

    body {
        background: white url("images/background.jpg") no-repeat center Top;
    }
    

    3、刷新首页,可见首页中添加了一张背景图片


    ***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***
  • 相关阅读:
    Object-C,NSSet,不可变集合
    NYIST 860 又见01背包
    NYIST 1070 诡异的电梯【Ⅰ】
    HDU 1542 Atlantis
    HDU 4756 Install Air Conditioning
    CodeForces 362E Petya and Pipes
    HDU 4751 Divide Groups
    HDU 3081 Marriage Match II
    UVA 11404 Palindromic Subsequence
    UVALIVE 4256 Salesmen
  • 原文地址:https://www.cnblogs.com/guanfuchang/p/6258104.html
Copyright © 2011-2022 走看看