Example:
Template 1
<script>
function refresh_infos(element){
var id = "test"
$.ajax({
type: "POST",
url: '/part_update/',
data: {'id':id},
success: function(data) {
$('#testDIV').html(data);
}
});
}
</script>
<div id="testDIV"></div>
View
def part_update(request):
id = request.POST.get('id', "")
#/* get infomation */
infos = DB.objects.filter(id = id)
return render_to_response('supply/template.html', { 'infos': infos })
Template 2
{% for info in infos %}
<p>{{ info.id }}</p>
{% endif %}
Urls
adding:
(r'^/part_update/$','part_update'),
2013年3月11日 星期一
2013年3月9日 星期六
[Codeigniter]ajax upload
Simple Example:
Controller:
public function upload_file(){
$file_element_name = $_POST['file_element_name'];
$config['file_name'] = "test.jpg";
$config['upload_path'] = "/upload/";
$config['allowed_types'] = 'gif|jpg|png|doc|txt|pdf';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = FALSE;
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name)){
$status = 'error';
$msg = $this->upload->display_errors('', '');
}else{
$data = $this->upload->data();
$file_id = true;
if($file_id){
$status = "success";
$msg = "File successfully uploaded";
}else{
unlink($data['full_path']);
$status = "error";
$msg = "Something went wrong when saving the file, please try again.";
}
}
@unlink($_FILES[$file_element_name]);
}
$upload_info = $this->upload->data();
echo json_encode( array(
"status" => $status,
));
}
View:
<form method="post" action="" id="form">
<input type="file" name="file" id="file" />
</form>
<script type="text/javascript">
$(function() {
$('#form').submit(function(e) {
$.ajaxFileUpload({
url :'<?=site_url("upload/")?>',
secureuri :false,
fileElementId :'file',
dataType : 'json',
data : {
'file_element_name' : 'file'
},
success : function (data){
alert(data.status);
}
});
return false;
});
}
</script>
2013年2月21日 星期四
[Code_Note] 引用外部API - 設計排版
在設計排版部分,可以將外部API獨立成method,
只要將需要的資料利用變數丟入即可
這樣可以加強程式的彈性
ex:
requestData("1")
def requestData(a):
request_data =
'''<%s xmlns="urn:ebay:apis:eBLBaseComponents">'''%a
只要將需要的資料利用變數丟入即可
這樣可以加強程式的彈性
ex:
requestData("1")
def requestData(a):
request_data =
'''<%s xmlns="urn:ebay:apis:eBLBaseComponents">'''%a
2013年1月30日 星期三
[Django] 如何取得django form資料
先簡單記錄一下,如何在python後台取得前端傳送的django form資料:
if request.method == "POST":
form = xxForm(request.POST , prefix='fd')
if form.is_valid(): # 通過驗證才可取得資料
print form.cleaned_data['col']
else:
print "It's not from POST !!"
2013年1月21日 星期一
[Python] 開發環境檔案夾選擇
小技巧:
在不同系統中可以建立多個不同變數:
local_folder = 'D:/projects/a'
online_folder = '/django_projects/b'
利用if判斷讓系統自行判斷存入資料夾
if os.path.exists(local_folder):
base_folder = local_folder
if os.path.exists(online_folder):
base_folder = online_folder
2012年9月2日 星期日
[Django-Firebird] Django連結Firebird整理
首先:
檔案部分位於:
Django 1.3 (or higher) > django-firebird
Django 1.4 > django-firebird driver on github
安裝前有一些必須事先安裝的套件:
在安裝時,直接將firebird檔案夾放置於兩個檔案夾下
這樣應該就可以順利使用嚕!
更詳細的敘述見參考資料。
參考資料:
http://stackoverflow.com/questions/11930701/django-firebird-can-not-work
http://code.google.com/p/django-firebird/
檔案部分位於:
Django 1.3 (or higher) > django-firebird
Django 1.4 > django-firebird driver on github
安裝前有一些必須事先安裝的套件:
- KInterbasDB package (http://www.firebirdsql.org/en/python-driver/)
- Get django 1.3 (http://www.djangoproject.com/download/)
- 也可以直接利用 pip 取得 > pip install django==1.3
在安裝時,直接將firebird檔案夾放置於兩個檔案夾下
- C:\Python27\Lib\site-packages\django\contrib\gis\db\backends
- C:\Python27\Lib\site-packages
這樣應該就可以順利使用嚕!
更詳細的敘述見參考資料。
參考資料:
http://stackoverflow.com/questions/11930701/django-firebird-can-not-work
http://code.google.com/p/django-firebird/
[Python] Virtualenv 安裝問題 - on mac
前言:
最近開始設置工作的環境,主要的環境是:
Python + Django + Firebird
來開發網站!
之前都是利用Windows設置環境,不過這是第一次設置在Mac OS上。
首先開始找尋設置專案的一些工具,就先記錄下來!
1. Virtualenv -- 可建置開發的虛擬環境
2. Pip -- Python 的套件管理工具
基本介紹和使用方法就問Google大神唄!
主題:
在設置Virtualenv時,進行建置環境資料夾時總是會發生錯誤...
執行時都會出現問題:
雖然一開就可以知道是沒有__init__.py檔案的關係!沒錯就這麼容易...
不過!不對阿,Python是mac裡內建的,沒有這檔案我要怎麼辦....
解決方法:
其實解決方法非常容易! 首先進入(cd)
接著執行:
就可以正常的建立專案資料夾嚕:)
參考資料:
Python can't locate distutils_path on Mac OSX
最近開始設置工作的環境,主要的環境是:
Python + Django + Firebird
來開發網站!
之前都是利用Windows設置環境,不過這是第一次設置在Mac OS上。
首先開始找尋設置專案的一些工具,就先記錄下來!
1. Virtualenv -- 可建置開發的虛擬環境
2. Pip -- Python 的套件管理工具
基本介紹和使用方法就問Google大神唄!
主題:
在設置Virtualenv時,進行建置環境資料夾時總是會發生錯誤...
virtualenv [Project_Name] --no-site-packages執行時都會出現問題:
....
IOError: [Errno 2] No such file or directory: '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/__init__.py'
....
雖然一開就可以知道是沒有__init__.py檔案的關係!沒錯就這麼容易...
不過!不對阿,Python是mac裡內建的,沒有這檔案我要怎麼辦....
解決方法:
其實解決方法非常容易! 首先進入(cd)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/接著執行:
sudo touch __init__.py就可以正常的建立專案資料夾嚕:)
參考資料:
Python can't locate distutils_path on Mac OSX
訂閱:
文章 (Atom)