我的django应用程序中有一个现有的views.py文件,如下所示:
from django.shortcuts import render
def segment_image(request):
if request.method == 'POST':
form = segment_form()
else:
if form.is_valid():
info = request.POST['info_name']
output = script_function(info)
return render(request, 'your_app/your_template.html', {
'output': output,
})
return render(request, 'your_app/your_template.html', {
'form': form,
})
def script_function(info):
'''here goes my main logic'''
x=y=w=h=102
return x,y,w,h
曾经与django模板和django形式进行交互。但是,现在我正在将所有内容转移到角度前端应用程序,所以我用角度$ http帖子替换了表单。
的index.html
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4" ng-repeat="image in images track by image.pk">
<h3>
Image {{ image.pk }}
<button class="btn btn-warning" ng-click="deleteImage(image)">Delete</button>
<button class="btn btn-primary" ng-click="segmentImage(image)">Segment</button>
</h3>
<a href="{{ image.image }}">
<img class="img-responsive" ng-src="{{ image.image }}">
</a>
</div>
app.js
...
$scope.segmentImage = function(image)
{
$http({method:'POST', url:'127.0.0.1:8000/image/segment_image/', data:{'image': image}})
.then(function successCallback(response)
{
console.log('success')
},function errorCallback(response)
{
console.log('failed')
console.log(response.config)
console.log(response.statusText)
}
)};
...
现在我需要对我的views.py进行哪些更改,以便它可以从angularapp接收图像并将其传递给我的script_function,并将返回值(x,y,w,h)渲染回索引。 HTML