How to call a Python function within a Backbone.js view?

被刻印的时光 ゝ 提交于 2019-12-12 01:33:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!