2012年5月15日 星期二

[Django] Generating file to download with Django

最近在開發 Django 時遇到需產生檔案進行下載,

經閱讀 Django 官方文件與 Google 後整理如下。

要產生下載的動作需設定 Content-Disposition 標頭。

from django.http import HttpResponse

# 產生檔案
response = HttpResponse(mimetype='application/binary')
response['Content-Disposition'] = \
'attachment; filename=%s.pem' % filename
return response

2012年5月10日 星期四

[JavaScript] location.href 用法

最近在開發 Web 介面時發現,

實作點擊按鍵後進行頁面轉換 ex: demo.html --> temp.html

使用先前所學 onclick="location.href('temp.html')" 技術,

在 IE 瀏覽器中可執行。

但, Google Chrom & Firefox 卻無效果 ( 攤手 )

經「估狗」大神指導,發現將程式寫法改成 onclick="location.href='temp.html'"

一切問題就解決啦!!! ( 灑花 )




實際體驗區:

下面按鍵使用 Google Chrom 跟 Firefox 無效果!



下面按鍵使用 IE, Chrom & Firefox 皆可!