static1 TIL230410 django에서 js안에서 static 경로를 쓰는 방법 -문제- 왜 js에서 static을 못 쓰는거지? 이미지를 모든 곳에서 못 받는 것 같은데? -환경- vscode django의 settings.py STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ] -원인- js안에서는 장고의 static 경로를 쓸 수 없다. -해결안 및 실행- html에서 js를 불러오는 안에 data-static-url="{% static 'imgs/' %}"를 넣고 js에서 const STATIC_URL = document.querySelector('script[src$="(js이름).js"]').dataset.staticUrl; 를 써서 ${STATIC_URL}(그림).png 이라는 정.. django 2023. 4. 10. 이전 1 다음