dajaxice.core.js 未在 ajax.py 中使用函数进行更新



我正在使用dajaxice(0.5.4)运行Django(1.4.3)。我在主项目文件夹中有一个名为 prj 的文件ajax.py我的函数,如下所示:

from dajax.core import Dajax
from dajaxice.decorators import dajaxice_register
from django.utils import simplejson
from dajaxice.core import dajaxice_functions
from django.core.urlresolvers import reverse, resolve
def getContent(request, *args, **kwargs):
    url = kwargs['url']
    try:
        v = resolve(url)
    except:
    data = []
    data.append(('some','data'))
    return simplejson.dumps(data)
dajaxice_functions.register(getContent)

我运行了python manage.py collectstatic,并得到以下输出:

Copying '/tmp/tmpm8OlOw'

但是,生成的dajaxice.core.js根本没有我的函数getContent。我哪里出错了?我希望我已经正确安装了dajaxice和一切。

看来你忘了从urls.py打电话给dajaxice_autodiscover()(这是Dajaxice作者推荐的地方)

此调用将加载 ajax.py 模块,并使其方法可由JS代码生成器发现

您需要

使用装饰器或文档中提到的其他方法向dajaxice注册@dajaxice_register函数。

http://django-dajaxice.readthedocs.org/en/latest/quickstart.html#create-your-first-ajax-function

最新更新