I am trying to send a ajax request to my views.py but I dont know how to use the path.
My views is located on my server at /home/pycode/main/main/apps/builder/views.py.
The page I am sending the request from is located at /home/dbs/www/python.html
Do I need to add something to my urls.py?
views.py
#!/usr/bin/env python26
from django.http import HttpResponse
def main(request):
return HttpResponse("from python with love")
python.html jquery ajax
<script language="JavaScript">
$(document).ready(function() {
$("#myform").submit(function() {
var myCheckboxes = new Array();
$("input:checked").each(function() {
myCheckboxes.push($(this).val());
});
$.ajax({
type: "POST",
url: '/main',
data: { myCheckboxes:myCheckboxes },
success: function(response){
alert(response);
}
});
return false;
});
});
</script>
To access functions in views you refer to them through their entries in
urls.pynever through their location in the filesystem.Going through the django tutorial (4 pages) will help immensely.
https://docs.djangoproject.com/en/dev/topics/http/urls/
in urls.py you map a url to a function using an entry similar to:
Then whenever you type ‘/main/` as a url it maps to your view function.