0
0

Djangoのstaticファイル

Posted at

static

Djangoで静的ファイル(js css image)等を使用する際に使います。
サーバーで動的な動きをしないファイルですね。

Djangoでは以下のようなディレクトリ構造なのでtest_web内にstaticディレクトリを打ち込みます。

.test
├── db.sqlite3
├── manage.py
├── test_app
│   ├── __init__.py
│   ├── ////省略////
└── test_web
    ├── __init__.py
    ├── templates
    ├── models.py
    ├── urls.py
    ├── views.py
    └── test_web  <---ココ
        ├── js
        ├── css
        └── images

setting

セッティングファイルに以下のコードを書いておけば問題ないです。

STATIC_URL = 'static/'

staticファイルの読み込み

面倒というか面倒というか忘れがちなのが
{% load static %}
という記述で

{% load static %}
<script src="{% static 'js/quiz.js' %}"></script>

このようにloadさせないとhtmlでjsを上手く読み込んでくれないようです。

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