问题
I'm working on a project that's in the process of migrating from Django 1.3
to Node/Backbone.js
Consequently, I'm working with two sets of views. I have a function for validating and processing images to be uploaded via a form, written in Python using PIL, that was originally designed for use in the Django views; however, the view that handles forms has since been migrated to Backbone.
I don't expect it to be an optimal solution, but for the sake of expediency I wondered if there's a way to call this as a standalone Python script (just to do the image processing) within the Backbone form view?
The crux of the problem is that the new JavaScript view is updating the database via PUT, whereas the original Django code used POST. I'm trying to avoid using two separate views on the same form and commingling the two methods, since the JavaScript view is perfectly capable of handling the file upload itself; however, I would like to avoid having to rewrite the imaging script using a new library.
From looking at some other threads, it seems that making an AJAX request might be the way to go, e.g. something along these lines, but the only examples I've found use jQuery, whereas I feel like there should be a similar way of doing it using Backbone's built in AJAX functionality.
来源:https://stackoverflow.com/questions/14430940/how-to-call-a-python-function-within-a-backbone-js-view