장고 애플리케이션의 모든 각도 코드 인 각도 4/장고 애플리케이션이 있습니다. 각도 앱은 webpack을 사용하여 제작되었습니다.Webpack : 장고와 함께 사용하기위한 index.html 생성
.js 번들을 "정적"폴더에, "index.html"파일을 "템플릿"폴더에 출력하려면 webpack을 사용하고 싶습니다. 여기
{% load static %}
<script type="text/javascript" src="{% static 'dist/polyfills.js' %}"></script>
가
project
최상위이 들고 내 디렉토리 구조 (간결함을 위해 생략 일부 파일)입니다 : 주입 된
<script></script>
태그는 장고의 "정적 파일"표기법을 사용하도록 업데이트해야합니다 장고 프로젝트.
project
+ angular
+ app (angular application root)
+ config
+ node_modules
+ src
- webpack.config.js
+ static
+ dist (webpack output folder)
- app.[hash].js
- vendor.[hash].js
- polyfills.[hash.js
- index.html
+ templates
- index.html
- 참고 : 나는 복사/아주 쉽게 index.html을 이동할 수 있습니다 알고 있지만, 나는 또한 장고의 정적 파일을 사용하여 태그가 필요합니다.
설명을 위해. Django가 제공하는 현재 "templates/index.html"파일입니다. 이것은 정상적으로 작동합니다. 가능하다면 webpack에서이 파일을 생성하고 싶습니다. 왜냐하면 dis 파일의 이름을 지정하는 데 [hash]를 사용하고 자동으로 업데이트해야하기 때문입니다. 따라서 app.[hash].js
, vendor.[hash].js
, polyfill.[hash].js
이 있고 내 각형 앱이 webpack에 의해 빌드 될 때 Django 템플릿이 업데이트됩니다.
템플릿/index.html을
{% load static %}
<html>
<head>
<base href="/">
<title>App</title>
<link href="{% static 'dist/app.css' %}" rel="stylesheet">
</head>
<body>
<my-app>Loading...</my-app>
<script type="text/javascript" src="{% static 'dist/polyfills.js' %}"></script>
<script type="text/javascript" src="{% static 'dist/vendor.js' %}"></script>
<script type="text/javascript" src="{% static 'dist/app.js' %}"></script>
</body>
</html>
이것은 잘못된 방향입니다. index.html은 Django가 렌더링 한 다음 Angular에서 사용하는 템플릿이어야합니다. –
예, 이해하고 있으며 현재 구현 방법입니다. 내가 원하는 것은 Webpack이 Django 용 템플릿 파일을 생성하여 이름에 [해시]가 포함 된 번들을 생성 할 수 있고 django가 파일 이름을 인식 할 수 있도록하는 것입니다. – Codewise