【发布时间】:2017-02-24 09:35:19
【问题描述】:
我有这样的应用结构:
├── 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找到其他静态文件怎么找不到?
【问题讨论】:
-
您是否尝试运行
tsc命令(或tsc main.ts)来编译您的ts 文件? -
是的。我在同一目录中拥有所有
.js、.js.map和.ts文件 -
看看下面的答案。
标签: python django angular frontend