dajaxice实现既不给出任何错误也不工作

2024-06-28 19:56:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是formwizard中的Dajaxice,它处于一个非常混乱的状态,因为它既不显示任何错误,也不显示输出。我的代码如下:

在阿贾克斯.py在

from django.utils import simplejson
from dajaxice.decorators import dajaxice_register

@dajaxice_register
def sayhello(request):
   return simplejson.dumps({'message':'Hello World'})

在网址.py在

^{pr2}$

向导1.html

{% block head %}
{% dajaxice_js_import %}
<title>My base template</title>

<script type="text/javascript">
function my_callback(data){alert(data.message);alert("Hello");}
</script>
{% endblock %}

{% block content %}
<input type="button" onclick="Dajaxice.trusform.dajaxice.core.sayhello(my_callback)" value="Get message from server!">
{% endblock %}

Django项目

trustform
  manage.py
  trustform
    ajax.py
    forms.py
    urls.py
    settings.py
  dajaxice
    dajaxice.core.js
  templates
    wizard1.html

能否请您特别谈谈路径结构,特别是onclick方法,因为我怀疑这是由于错误的路径,但不确定。在


Tags: frompyimportregistermessagehellotitlehtml
1条回答
网友
1楼 · 发布于 2024-06-28 19:56:54

尝试更换

Dajaxice.trusform.dajaxice.core.sayhello

^{pr2}$

因为sayhello方法是应用程序的一部分。另外,你在trustform中漏掉了“t”,所以也加上这个。在

相关问题 更多 >