0

如文档所述,我安装了 dajaxice 和 dajax。我尝试了 dajaxice,它是 alert() 的例子,它奏效了。然后我尝试了dajax。我想在我的网站上制作多个示例。Pokervalue 是项目名称,锦标赛是应用程序名称。 安装 dajax:

$ pip install django_dajax

很好 将 dajax 添加到设置 -> INSTALLED_APPS

'dajax',

包括这个文件
乘法示例: ajax.py 在我的 app 文件夹中。

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

@dajaxice_register
def multiply(request, a, b):
    dajax = Dajax()
    result = int(a) * int(b)
    dajax.assign('#result','value',str(result))
    return dajax.json()

这是我的模板文件的一部分:

<form class="form-inline" action="#">
<input type="text" value="5" id="a"> x
<input type="text" value="6" id="b"> =
<input type="text" value="" id="result">
<input type="button" value="Multiply!" onclick="calculate();">
</form>

这是在<head>

<script type="text/javascript">
function calculate(){
    Dajaxice.tournament.multiply(Dajax.process,{'a':$('#a').val(),'b':$('#b').val()})
}
</script>

由于 dajaxice 正在工作,我认为 dajax 存在问题。我错过了什么/不明白。


编辑 1: 在我的 runserver 中它说:

[01/Sep/2014 14:48:17] "POST /dajaxice/tournament.multiply/ HTTP/1.1" 200 62
[01/Sep/2014 14:48:17] "POST /dajaxice/tournament.multiply/ HTTP/1.1" 200 62
[01/Sep/2014 14:48:21] "POST /dajaxice/tournament.multiply/ HTTP/1.1" 200 62
[01/Sep/2014 14:57:18] "POST /dajaxice/tournament.multiply/ HTTP/1.1" 200 62

所以我尝试加载/dajaxice/tournament.multiply/. 我得到 FunctionNotCallableError。我用谷歌搜索,它发生在 collectstatic 没有运行时。所以我再次运行它。

./manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /var/www/django/pokervalue/wsgi/static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
/usr/local/lib/python2.7/dist-packages/dajax/core.py:1: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

WARNING:py.warnings:/usr/local/lib/python2.7/dist-packages/dajax/core.py:1: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

Copying '/tmp/tmphIfJ7X'

1 static file copied to '/var/www/django/pokervalue/wsgi/static', 234 unmodified.

但它没有帮助,我仍然得到 FunctionNotCallableError。


编辑 2
据此我缺少 dajaxice_autodiscover()。但是我的主应用程序文件夹和锦标赛应用程序文件夹中都有 dajaxice_autodiscover() ,在 urls.py 文件中。

4

0 回答 0