【问题标题】:Displaying image url from django template显示来自 django 模板的图像 url
【发布时间】:2011-11-17 01:57:40
【问题描述】:

这是一个非常基本的问题 -

我有一个名为 Book 的模型,它有一个属性 imageURL(它是一个字符域)。

我有这个模板代码 -

<text class= "text" id = "bookTitle">{{ book.title|safe }}</text><br/>
                <text class= "text" id= "bookAuthor">by {{ book.author|safe }}</text><br/>
                <img src= str(book.imageURL) class = "result" />

但是,str(book.imageURL) 总是返回一个 unicode 值(因为 Django 模型就是这样做的?) - 我怎样才能获取字符串 url 以便我可以把它放在这里?

谢谢

【问题讨论】:

标签: html django django-templates


【解决方案1】:

模板代码无效,试试这个:

<text class= "text" id = "bookTitle">{{ book.title|safe }}</text><br/>
                <text class= "text" id= "bookAuthor">by {{ book.author|safe }}</text><br/>
                <img src="{{ book.imageURL }}" class = "result" />

【讨论】:

    猜你喜欢
    • 2015-12-17
    • 1970-01-01
    • 2014-06-04
    • 2016-12-13
    • 2021-05-18
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多