美文网首页光阴的故事明月共光辉
Writing my first Django app - 7

Writing my first Django app - 7

作者: 游文影月志 | 来源:发表于2020-08-04 10:33 被阅读0次

    Aside from the HTML generated by the server, web applications generally need to serve additional files — such as images, JavaScript, or CSS — necessary to render the complete web page. In Django, these files are called "static files".

    1. Customize my app's look and feel

    First, create a directory called static in the polls directory. Django will look for static files there.

    Within the static directory that has just created, create another directory called polls and within that create a file called style.css.

    polls/static/polls/style.css

    li a {
        color: green;
    }
    

    polls/templates/polls/index.html

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

    Start the server (or restart it if it's already running):

    py manage.py runserver
    

    Reload http://localhost:8000/polls/ and the question links are green now.

    2. Adding a background-image

    Create an images subdirectory in the polls/static/polls/ directory. Inside this directory, put an image called background.jpg.

    polls/static/polls/style.css

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

    Reload http://localhost:8000/polls/ and the background will be loaded in the top left of the screen.

    相关文章

      网友评论

        本文标题:Writing my first Django app - 7

        本文链接:https://www.haomeiwen.com/subject/wbgirktx.html