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
精彩评论