python - 在 Angular 4 模板中使用 django 标签?

标签 python django angular

我在 DjangoAngular 4 前端中有一个 Web 服务器,但我的问题是我无法在 Angular 模板中使用 Django 标签。

例如

我有这个index.html,就像/templates(django)中的根目录

{% load static %}
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>TrackerFrontend</title>
    <base href="{% static %}">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link
      href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
    <!--<link
         rel="stylesheet"
         type="text/css"
         href="http://fonts.googleapis.com/css?family=Fontin">
     Not work
       -->
  </head>
  <body>
    <app-root>Loading...</app-root>
    <script type="text/javascript" src="{% static 'inline.bundle.js' %}"></script>
    <script type="text/javascript" src="{% static 'polyfills.bundle.js' %}"></script>
    <script type="text/javascript" src="{% static 'styles.bundle.js' %}"></script>
    <script type="text/javascript" src="{% static 'vendor.bundle.js' %}"></script>
    <script type="text/javascript" src="{% static 'main.bundle.js' %}"></script>
  </body>
</html>

如果我尝试从我的服务器调用媒体文件,我可以看到这个

<img src="{% get_media_prefix %}/images/2017-08-12-19-28-20st1folio1.png">

但是当我复制并粘贴相同的 img 标签,在我的项目 Angular 中执行 npm run build 并再次运行我的服务器时,我在终端中收到错误

Template parse errors:
Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)

这个index.html是前端应用程序中真实的副本,但我添加了{% load static %}和其他标签来调用bundle.js文件。

可以在每个 Angular 组件内部复制调用 {% load static %} 吗?

无需执行npm run build也会出现相同的错误

最佳答案

改变 <img src="{% get_media_prefix %}/images/2017-08-12-19-28-20st1folio1.png"><img src="{{ get_media_prefix }}/images/2017-08-12-19-28-20st1folio1.png">

关于python - 在 Angular 4 模板中使用 django 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45664172/

相关文章:

Python正则表达式分割但将正则表达式匹配的结束部分放回到字符串中?

python - 将列添加到 Tfidf 矩阵

python - 显示价格

angular - 测试 - stub 服务方法未定义

html - angular2-date-picker - 仅显示当前日期时间

angular - 如何使用 Entity Effects 扩展 ngrx/data?

python - ValueError : Error when checking input: expected dense_151_input to have 3 dimensions, 但得到形状为 (2, 2100) 的数组

c# - Python 等同于 C# 的 .Select?

django 通过电子邮件进行用户注册和身份验证

html - 超出 Django 最大递归深度。查看无限循环