我尝试使用 dajaxice 来刷新我的表格,但我看到了一个错误。
追溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/bank/index1/
Django Version: 1.5.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'meli',
'django_tables2',
'dajaxice',
'django_jalali')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
187. response = middleware_method(request, response)
File "/usr/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
26. patch_vary_headers(response, ('Cookie',))
File "/usr/lib/python2.7/site-packages/django/utils/cache.py" in patch_vary_headers
142. if response.has_header('Vary'):
Exception Type: AttributeError at /bank/index1/
Exception Value: 'str' object has no attribute 'has_header'
这是我的看法:
def index1(request):
data = MelliTable(ModelMelli.objects.filter(check=False))
RequestConfig(request, paginate={'per_page': 20}).configure(table)
table = render_to_string('meli/index.html', {'data': data })
return simplejson.dumps({'table':table})
dajaxice_functions.register(index1)
我的js是:
<script>
function my_callback(data){
if(data!=Dajaxice.EXCEPTION){
document.getElementById('test').innerHTML = data.table;
}
else{
alert('Error');
}
}
</script>