2013-06-26 144 views
3

使用Dajaxice我想將參數傳遞給python函數。dajaxice:將參數傳遞給python函數

在HTML文件中,我有以下聲明

<a href="#" onclick="Dajaxice.myapp.sayhello(Dajax.process,{'dir':3})"> <i class="icon"></i></a> 

,在我ajax.ps文件我具備的功能

@dajaxice_register 
def sayhello(request, dir): 
    print(dir) 

它正常工作,如果我刪除第二個參數DIR在兩個html和python文件,但有了dir,我得到錯誤信息「出錯了」。

有沒有人知道這可能是什麼問題?

+0

您是否試圖在decorator中爲sayhello函數指定'method ='GET''?只是爲了檢查。 – maulik13

+0

嗯,我想你在這裏有一個觀點。如果我用method ='GET'註冊它,我得到錯誤消息: dajaxice_register()得到了一個意外的關鍵字參數'method'。你知道這是爲什麼嗎?看起來安裝可能有缺陷? – user695652

+0

這很奇怪。你知道調用堆棧中發生這種異常嗎?你使用的是什麼版本的dajaxice?在最新的GitHub代碼中,我沒有看到這樣的例外,除非我錯過了某些東西。 – maulik13

回答

1

,如果你使用Python 3 *,然後在模塊dajaxIce進行更改文件VENV/lib目錄/ python3.2 /站點包/ dajaxice/views.py

def safe_dict(d): 
     """ 
     Recursively clone json structure with UTF-8 dictionary keys 
     http://www.gossamer-threads.com/lists/python/bugs/684379 
     """ 
     if isinstance(d, dict): 
      return dict([(k, safe_dict(v)) for k, v in d.items()]) 
     elif isinstance(d, list): 
      return [safe_dict(x) for x in d] 
     else: 
      return d 
0

變化的SayHello到:

def sayhello(request): 
    my_dict=json.loads(request.POST['argv']) 
    dir=my_dict['dir'] 
    print(dir)