前提,実現したいこと
Django内で作成したプロジェクト内のアプリケーションにおけるTemplateで外部jsファイルを読み込みたい
Django==3.2です
プロジェクトフォルダ内
myproject/
├─ myproject/
│ ├─ __ init__.py
│ ├─ settings.py
│ ├─ urls.py
│ ├─ asgi.py
│ └─ wsgi.py
├─ myapp/
│ ├─ __ init__.py
│ ├─ admin.py
│ ├─ apps.py
│ ├─ migrations/
│ ├─ models.py
│ ├─ static/
│ │ ├─ myapp/
│ │ │ └─ js/
│ │ │ └─ index.js
│ ├─ templates/
│ │ └─ myapp/
│ │ ├─ index.html
│ │
│ ├─ tests.py
│ ├─ urls.py
│ └─ views.py
└─ manage.py
発生している問題・エラーメッセージ
(ブラウザのコンソール)
<script> のソース “http://127.0.0.1:8000/static/myapp/js/index.js” の読み込みに失敗しました。
該当のソースコード
settings.py
python
1... 2 3STATIC_URL = '/static/'
index.html
html
1.... 2 3{% load static %} 4<script src="{% static 'myapp/js/index.js' %}">
index.js
js
1console.log("success")
試したこと
staticフォルダの位置、パスの書き方、スペルミスがないかの確認
補足情報(FW/ツールのバージョンなど)
使用ブラウザ:Firefox
回答1件