[英]How to load angular2 files to Django template?
我有這樣的應用程序結構:
├── project
| |── templates
│ │ └── index.html
│ ├── __init__.py
│ ├── models.py
│ ├── urls.py
│ ├── serializers.py
│ ├── views.py
├── static
| ├── app
| │ ├── app.component.spec.ts
| │ ├── app.component.ts
| │ ├── app.route.ts
│ │ ├── component1.component.ts
| │ ├── component2.component.ts
│ │ └── main.ts
| ├── system.config.json
│ ├── tsconfig.json
│ └── typings.json
├── db.sqlite3
├── LICENSE
├── manage.py
並且我正在嘗試將angular2文件加載到django模板index.html
,因此文件如下所示:
{% load static from staticfiles %}
<!DOCTYPE html>
<html>
<head>
<base href=/ >
<title>Hello! </title>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.25?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js"></script>
<script>
System.import('{%static '/app/main' %}').catch(function(err){ console.error(err); });
</script>
<link href="{%static '/css/stylesheet.css' %}">
<link href="{%static '/css/bootstrap.min.css' %}">
</head>
<body>
<img src="{%static '/assets/logo.png' %}"></img>
<as-my-app>Loading...</as-my-app>
</body>
</html>
我的問題是所有靜態文件都可以正常加載,但是我的瀏覽器在加載/static/app/main
時不斷顯示錯誤,並說找不到。 如果Django找到其他靜態文件,為什么找不到它呢?
您嵌套了單引號,並且文件名是main.js
而不是main
,還需要刪除第一個/
。 讓我知道以下代碼行是否可以解決您的問題:
System.import("{% static 'app/main.js' %}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.