Jquery 如何从Django模板调用Dajax/Dajaxice函数
我正在编写一个简单的Django应用程序,并希望使用Dajax/Dajaxice添加ajax分页。我首先尝试从Dajax网站上实现简单的分页示例(http://dajaxproject.com/pagination/)-但还没能让它工作。每当我按下“下一步”按钮时,就会出现以下js错误:Jquery 如何从Django模板调用Dajax/Dajaxice函数,jquery,python,ajax,django,dajaxice,Jquery,Python,Ajax,Django,Dajaxice,我正在编写一个简单的Django应用程序,并希望使用Dajax/Dajaxice添加ajax分页。我首先尝试从Dajax网站上实现简单的分页示例(http://dajaxproject.com/pagination/)-但还没能让它工作。每当我按下“下一步”按钮时,就会出现以下js错误: Uncaught TypeError: Cannot call method 'pagination' of undefined 我的Django项目名为“DoSomething”——它包含一个名为“core
Uncaught TypeError: Cannot call method 'pagination' of undefined
我的Django项目名为“DoSomething”——它包含一个名为“core”的应用程序
我已按照所有说明在此处安装Dajaxice:
我在“core”目录中有一个名为“ajax.py”的python文件,其中包含以下代码:
from views import get_pagination_page
from dajax.core.Dajax import Dajax
from django.template.loader import render_to_string
from dajaxice.decorators import dajaxice_register
from django.utils import simplejson
@dajaxice_register
def pagination(request, p):
try:
page = int(p)
except:
page = 1
items = get_pagination_page(page)
render = render_to_string('posts_paginator.html', { 'items': items })
dajax = Dajax()
dajax.assign('#pagination','innerHTML',render)
return dajax.json()
My views.py文件包含以下方法:
def index(request):
posts = Post.objects.order_by('id').reverse()
items = get_pagination_page(1)
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
def get_pagination_page(page=1):
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.template.loader import render_to_string
items = Post.objects.order_by('id').reverse()
paginator = Paginator(items, 10)
try:
page = int(page)
except ValueError:
page = 1
try:
items = paginator.page(page)
except (EmptyPage, InvalidPage):
items = paginator.page(paginator.num_pages)
return items
我的索引模板包含以下内容:
<div id="pagination">
{% include "posts_paginator.html" %}
</div>
{%include“posts_paginator.html”%}
My posts_paginator.html模板包含以下链接,用于触发分页方法:
{% for i in items.object_list %}
{{ i }}<br>
{% endfor %}
{% if items.has_next %}
<a href="#" onclick="Dajaxice.core.pagination(Dajax.process,{'p':{{ items.next_page_number }}})">next</a>
{% endif %}
{items.object_list%中的i的%
{{i}}
{%endfor%}
{%if items.has_next%}
{%endif%}
我的问题是,在onClick值中,我应该如何引用分页方法(从我的ajax.py文件)。我找不到任何东西来解释这一点——我已经尝试了我能想到的所有项目名称/应用程序名称的组合
谢谢!:) 至少在我的例子中,我必须附加项目名称和app\u标签
Dajaxice.MyProject.core.my_dajax_method(Dajax.process, {'form' : data});
注意: