I'm trying to pass the parameters defined by a user in the front end to a python script being run on the server. I'm using a Django framework in the back end (probably too heavy for my purposes at the moment but wanted to give it a try). Here's the jQuery code I'm using to call the python fxn which is located at the defined url. The parameters I'd like to pass are in the data attribute.

    bbviz.onStart = (function() {
    $.ajax({
        type:'get',
        url:'http://localhost:8000/statview/simulation/',
        data:{url:'blackch02', 'profile':'current', 'sims':1000},
        async:'asynchronous',
        dataType:'json',
        success: function(data) {
            console.log(data);
        },
        error: function(error) {
            console.log(error);
        }
    });
});

And here's the Django view function:

def simulation(request):
    out = batterSim.sim_season(url, profile, sims)
    return out

I'm calling the batterSim module and running the sim_season function which has the same named parameters as the data attribute. The function then returns a json object that the front end would receive. So I'm trying to figure out how to take those parameters from the ajax function and use them in the python function.

share|improve this question

You can use parameter in Django view by call

request.GET['profile']
request.GET['sims']

You should read more about Django request : https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.GET

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.