Reputation: 1195
I am pretty new with Client side code and completely clueless when it comes to server-side (Django, in particular). What I am attempting to do is click a button which sends a get request to the server, and then posts it on the page (using jGlideMenu).
I know the code should look something like the following:
$('#clickID').click(function(){
$.ajax({
url:"someURLGoesHere",
type: 'GET',
success: function(data){
$('#someEl_2').html(data)
},
dataType: JSON
});
});
I have no idea what to use for the URL. Do I need to refer to the url.py file? views.py? models.py? Maybe a particular var inside one of those files? Also do I need to use relative directories?
All the tutorials I found use PHP instead so I am not sure if it is the same. Please help!
Upvotes: 0
Views: 816
Reputation: 4566
You put in whatever URL you have setup to go to the appropriate function to process the data in the views.py file. If you have this in your urls.py:
url(r'^/testing$','proj.app.testing')
you would put in '/testing'
for your ajax request.
Upvotes: 1
Reputation: 11588
If you want to insert the content from your Django app, you can use jQuery's load()
method:
$('#result').load('path/to/script.py');
You will need to hit a Python script which is publicly accessible. Whereas with other MVC frameworks, you'd hit the controller, because Django has a slightly different methodology, you will need to hit a view, since these control access to your models and handle most of the business logic:
In Django’s interpretation of MVC, the “view” describes the data that gets presented to the user; it’s not necessarily just how the data looks, but which data is presented. In contrast, Ruby on Rails and similar frameworks suggest that the controller’s job includes deciding which data gets presented to the user, whereas the view is strictly how the data looks, not which data is presented.
Upvotes: 1