python - DJANGO DATATABLES template not working -
i'm working on simple example using datatables fetch result templates not showing @ , there's no error in console ! html page : trial.html
{% load static %} <html> <head> <link rel="stylesheet" href="{% static "css/jquery.datatables.css" %}" type="text/css" /> <link rel="stylesheet" href="{% static "css/datatables.tabletools.css" %}" type="text/css" /> <link rel="stylesheet" href="{% static "js/jquery.js" %}" type="text/javascript" /> <link rel="stylesheet" href="{% static "js/jquery.datatables.js" %}" type="text/javascript" /> </head> <body> <table cellpadding="0" cellspacing="0" border="0" id="example"> <thead> <tr><th></th></tr> </thead> <tbody></tbody> </table> <script type="text/javascript" language="javascript" class="init"> $(document).ready(function() { $('#example').datatable( { dom: 't<"clear">lfrtip', "processing": true, "ajax": { "processing": true, "url": "{% url 'url' %}", "datasrc": "" }, tabletools: { "sswfpath": "http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf" } } ); } ); </script> </body> </html>
and simple view :
def mymodel_asjson(request): object_list = list(utilisateur.objects.values_list("login")) return httpresponse(json.dumps(object_list))
and urls :
urlpatterns = patterns('si.views', url(regex=r'^', view='mymodel_asjson', name='url'), )
urlpatterns = patterns('si.views', url(regex=r'^', view='mymodel_asjson', name='url'), )
there few issues in code: json call on root (i think that's 1 of issues) ! view mixes camel case , underscore. json call url name url
. apparently, return user logins better make code explicit:
urlpatterns = patterns('si.views', url(regex=r'^api/logins/', view='login_list', name='api-login-list'), )
change view name of course. test directly, go http://localhost/api/logins/
see if proper list. ideally, want functional test that.
finally, change in template: "url": "{% url 'api_login_list' %}",
also in view:
object_list = list(utilisateur.objects.values_list("login"))
shouldn't login
? no uppercase.
Comments
Post a Comment