首页 > 解决方案 > 无法在 django/ChatterBot 示例中使用 jQuery 的 .html(text) 方法加载图像

问题描述

ChatterBot 训练数据集

image_data.yml:

categories:
- myown
conversations:
- - show me famous book image?
  - <img src="{% static 'img/Book.png' %}"  height="50" width="50"> //this line is sent as **text** in $row.html(text); 

jQuery代码:

  function createRow(text) {
    var $row = $('<li class="list-group-item"></li>');

    $row.empty().html(text); //$row.html(text); #Both are not working
    $chatlog.append($row);
  }

应用程序.html:

{% load staticfiles %} //on top of file
...
..
...    
<ul class="list-group chat-log js-chat-log">
    //here <li class="list-group-item"></li> element will appended.
                            </ul>

错误:

GET http://127.0.0.1:8000/%7B%%20static%20'img/Book.png'%20%%7D 404 (Not Found)

问题是,它没有考虑{% load staticfiles %}. 这就是为什么它没有渲染我的图像。任何人都可以帮助我吗?

注意: 如果我提供在线图片链接作为来源,它就可以工作。但是,当我尝试提供完整的本地路径时,它会 not allowed to load local resource在 chrome 控制台中给出错误。

标签: javascriptjqueryhtmldjangochatterbot

解决方案


推荐阅读