django中使用Dajax的动态下拉菜单

时间:2014-06-10 09:30:23

标签: python django dajaxice dajax

我正在尝试使用dajax模块在django中实现简单的下拉菜单。

但我收到了错误

TypeError at /choice/dj
updatecombo() takes exactly 2 arguments (1 given)
Request Method: GET
Request URL:    http://127.0.0.1:8000/choice/dj
Django Version: 1.5
Exception Type: TypeError
Exception Value:    
updatecombo() takes exactly 2 arguments (1 given)
Exception Location: C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response, line 115
Python Executable:  C:\Python27\python.exe

我的views.py文件是

from dajax.core import Dajax
from dajaxice.decorators import dajaxice_register

@dajaxice_register
def updatecombo(request, option):
    dajax = Dajax()
    options = [['Madrid', 'Barcelona', 'Vitoria', 'Burgos'],
               ['Paris', 'Evreux', 'Le Havre', 'Reims'],
               ['London', 'Birmingham', 'Bristol', 'Cardiff']]
    out = []
    for option in options[int(option)]:
        out.append("<option value='#'>%s</option>" % option)
        print option
    dajax.assign('#combo2', 'innerHTML', ''.join(out))
    return dajax.json()

dajax.html文件是

<select onchange="Dajaxice.examples.updatecombo(Dajax.process, {'option':this.value})" size="1">
    <option value="0">Select...</option>
    <option value="0">Spain</option>
    <option value="1">France</option>
    <option value="2">United Kingdom</option>
</select>
<select id="combo2" onchange="" size="1"></select>

my urls.py

urlpatterns = patterns('choice.views',

                            (r'^dj$', 'updatecombo'),  

                       )

我在seetings.py文件中添加了'dajaxice' 我不知道我在做什么错,请帮我解决这个,,,,,,

0 个答案:

没有答案