0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Djangoスタートアップ その6(staticファイル編)

Last updated at Posted at 2023-02-26

staticフォルダの配置場所

myproject
├── (appName)
│   ├── migrations
│   ├── static
│   └── templates
└── otherApp

cssの追加場所

djangogirls
└─── (appName)
     └─── static
          └─── css
               └─── myCss.css

staticファイルのロード

appName/templates/appname/post_list.html
{% load static %}★staticファイルのロード(先頭に追加)
<html>
    <head>
        <title>Title/title>
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="{% static 'css/blog.css' %}">★cssファイルの読み込み
    </head>
    <body>
        <div>
            <h1><a href="/">Django Girls Blog</a></h1>
        </div>

        {% for post in posts %}
            <div>
                <p>published: {{ post.published_date }}</p>
                <h2><a href="">{{ post.title }}</a></h2>
                <p>{{ post.text|linebreaksbr }}</p>
            </div>
        {% endfor %}
    </body>
</html>

※staticファイルの読み込ませる場合は一回サーバーを再起動しないとだめ

参考記事
https://tutorial.djangogirls.org/ja/template_extending/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?