![](/img/trans.png)
[英]What is the best place to store ng-templates in Angular/Django SPA
[英]Where to put angular ng-templates in django project
我有很多這樣的ng-template
:
<script type="text/ng-template" id="item.html">
// content
</script>
現在,所有這些都位於一個base.html
文件中,因此模板代碼變得混亂。
我想將每個ng-template放在其自己的html文件中。
邏輯位置是templates
文件夾。 但是,當我嘗試引用諸如templates/ng-templates/item.html
類的templates/ng-templates/item.html
,出現404 Not Found
。
我該如何解決? 或者,實現此目標的最佳實踐是什么?
實際上,您應該將角度模板放置到靜態目錄中。 由於Django不提供模板,因此它使用模板進行渲染。
因此,例如,您可以將模板放置在/static/templates/item.html
,並按一定角度引用此模板,例如/{{ STATIC_URL }}/templates/item.html
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.