can't make dajax example make work - FunctionNotCallableError

别说谁变了你拦得住时间么 提交于 2020-01-06 14:40:26

问题


I installed dajaxice and dajax as docs mentioned. I tried dajaxice and it's alert() example and it worked. Then I tried dajax. I would like to make multiply example work on my website. Pokervalue is project name and tournament is app name. Install dajax:

$ pip install django_dajax

went fine Added dajax to settings -> INSTALLED_APPS

'dajax',

Included this file.
Multiplication example: ajax.py is in my app folder.

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()

This is part of my template file:

<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>

and this is in <head>:

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

Since dajaxice is working, I assume there is a problem with dajax. What am I missing/don't understand.


EDIT 1: In my runserver it says:

[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

So I tried to load /dajaxice/tournament.multiply/. I get FunctionNotCallableError. I googled and it occures when collecstatic was not run. So I run it again.

./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.

But it didn't help and I still get FunctionNotCallableError.


EDIT 2
According to this, I am missing dajaxice_autodiscover(). But I have dajaxice_autodiscover() in both, my main app folder as well as tournament app folder , in urls.py file.

来源:https://stackoverflow.com/questions/25608071/cant-make-dajax-example-make-work-functionnotcallableerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!