본문 바로가기

Development (Python, Django, C..)

[Django] Tutorial 따라하기 - 6

* reference : https://docs.djangoproject.com/ko/2.1/intro/tutorial06/

 

첫 번째 장고 앱 작성하기, part 6 | Django 문서 | Django

Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate

docs.djangoproject.com

 

 

#. Change APP



-- Change Style sheet
(djenv) ivan@django:~/djgo$ more polls/static/polls/style.css

li a { 
    color: green; 
} 


-- Load static on index.html
(djenv) ivan@django:~/djgo$ more polls/templates/polls/index.html

{% load static %}

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

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}


-- Run Server again

(djenv) ivan@django:~/djgo$ python manage.py runserver 0:8000
Performing system checks...

System check identified no issues (0 silenced).
November 27, 2019 - 09:02:14
Django version 2.0.13, using settings 'mysite.settings'
Starting development server at http://0:8000/
Quit the server with CONTROL-C.
[27/Nov/2019 09:02:35] "GET /polls/ HTTP/1.1" 200 160
[27/Nov/2019 09:02:35] "GET /static/polls/style.css HTTP/1.1" 200 28


-- browsing : http://192.168.56.200:8000/polls/

 

 


 



#. Add background image


-- locate background.jpg on polls/static/polls/style

(djenv) ivan@django:~/djgo$ ls -al polls/static/polls/background.jpg
-rw-rw-r-- 1 ivan ivan 4460082 Nov 29 04:25 polls/static/polls/background.jpg



-- change style.css


(djenv) ivan@django:~/djgo$ more polls/static/polls/style.css

li a {
    color: green;
}

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


-- runserver


drwxrwxr-x 6 ivan ivan 4096 Nov 27 08:59 polls
(djenv) ivan@django:~/djgo$ python manage.py runserver 0:8000
Performing system checks...

System check identified no issues (0 silenced).
November 27, 2019 - 09:02:14
Django version 2.0.13, using settings 'mysite.settings'
Starting development server at http://0:8000/
Quit the server with CONTROL-C.
[27/Nov/2019 09:02:35] "GET /polls/ HTTP/1.1" 200 160
[27/Nov/2019 09:02:35] "GET /static/polls/style.css HTTP/1.1" 200 28
[29/Nov/2019 04:28:52] "GET /polls/ HTTP/1.1" 200 160
[29/Nov/2019 04:28:52] "GET /static/polls/style.css HTTP/1.1" 200 101
[29/Nov/2019 04:28:52] "GET /static/polls/images/background.jpg HTTP/1.1" 404 1710
[29/Nov/2019 04:28:55] "GET /polls/ HTTP/1.1" 200 160

--> Error occurs


-- move to right directory

(djenv) ivan@django:~/djgo$ ls polls/static/polls/images/background.jpg
polls/static/polls/images/background.jpg



-- Check on browser

OK