开发者

Caching large html fragments in Django and passing them to the template when they contain smart quotes

I'm using urllib2 to open and read two external web pages and then saving them to django's internal cache, like so:

header = urllib2.urlopen( "http://www.mysite.com/pageheader.html" ).read()
footer = urllib2.urlopen( "http://www.mysite.com/pagefooter.html" ).read()

cache.add( 'header', header )
cache.add( 'footer', footer )

I then retrieve these from cache and pass them as template variables:

integration = cache.get_many[(开发者_如何学运维'header','footer')]

The problem appears to be non-ascii characters in one of the fragments preventing it from displaying on the template. These seem to be smart quotes and in vim they appear as:

We<92>ve or <93>Tumultuous<94> or just <97>

Since I have no access to the remote server, is there a way when grabbing these fragments that I can convert these problems before saving them to cache?


Check if urllib2 can properly encode retrieved page, more here:

urllib2 read to Unicode

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜