Python jQuery将图片URL转换为img 标签方法是什么,,后端使用的是Flask,
Python jQuery将图片URL转换为img 标签方法是什么,,后端使用的是Flask,
后端使用的是Flask,前端是jQuery Mobile。后端会传一段字符串给前端,这段字符串中会有类似于“http://xxx.jpg”这样的图片URL。现在想要将这个URL直接替换成<img src="http:///xxx.jpg">这样的标签,然后在页面上输出。试着在后端进行正则表达式的替换,结果会出现错误,我的代码如下:
<!DOCTYPE html><html><head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script></head><body> <div data-role="page" id="pageone"> <div data-role="header" data-fullscreen="true"> <a href="/admin/" data-role="button">首页</a> <h1>产品详情</h1> </div> <div data-role="content"> <div data-role="fieldcontain"> <h2>{{ product.name }}</h2> </div> <hr> <div data-role="fieldcontain"> <div id="desc"></div> </div> </div> </div> <script> var txt = {{ product.description}}; $('#desc').text(txt); </script> <div data-role="footer" data-fullscreen="true"> <h1>联系方式</h1></div></body></html>
其中,var txt = {{ product.description}};一句,如果不换成var txt = {{ product.description|tojson|safe}};的话就会什么也不输出。
干嘛不直接把{{ product.description}}对应的内容编译进html里,编译进js再操作有点多此一举。。。
编橙之家文章,
相关内容
- python-2.7.5.amd64跑程序时报错ImportError: No module named win3
- Python线程报错AttributeError怎么解决,,在一个文件中写了
- 可以将Python脚本变成能被调用的模块吗?,python脚本,以
- 获取文件MIME type Python什么方法可以实现,,文件的扩展
- flask项目导入报ValueError什么意思?,flaskvalueerror,项目结
- 为什么python输出数据时间比C++长,python输出,C语言中,
- Python Scrapy startproject错误异常代码修改求助,scrapystar
- Python access数据库pywintypes.com_error是什么问题,,使用Py
- 如何优化python mongodb批量修改任务,pythonmongodb,有一千万
- Function Annotation在python 2.7中使用有什么注意事项?,ann
评论关闭