【问题标题】:Dajax Hello World达贾克斯你好世界
【发布时间】:2013-10-05 17:14:27
【问题描述】:

我似乎无法从 Dajax 那里得到一个简单的 hello world 响应,在为 hello world 工作了一整天之后。 (我相信你会意识到这是 hello world 指南中逐字逐句的)

我有一个应用程序文件夹示例:proj/apps/myapp

我在 myapp 中创建了 ajax.py:

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

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

我有我的模板:

{% load dajaxice_templatetags %}

<html>
  <head>
    <title>My base template</title>
    ...
    {% dajaxice_js_import %}
  </head>
  <script type="text/javascript">
    function my_js_callback(data){
      alert(data.message);
    }
  </script>
    <input type="button" onclick="Dajaxice.myapp.sayhello(my_js_callback);" value="test">
</html>

这不起作用。我还按照安装指南逐字逐句找到:http://django-dajaxice.readthedocs.org/en/latest/installation.html

任何帮助将不胜感激。我感觉我快疯了。

【问题讨论】:

  • 您是否正确地为 dajax 静态文件提供服务?我相信dajaxice_js_import 会自动检查您的静态网址是否配置正确,但手动验证也无妨。检查您的 Web 控制台,看看它是否正确加载了 dajaxice js。
  • @RomanAlexander 是的,我在 URL 中设置了它来提供文件,我可以从 runserver 看到它正在适当地提取静态文件。
  • 我是个白痴。我忘了一个右括号。感谢@RomanAlexander 调查。

标签: python django dajaxice dajax


【解决方案1】:

在 OP 最初的努力中省略了右括号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2014-11-30
    • 2015-01-13
    相关资源
    最近更新 更多