最简单的方法可能只是构建一个AJAX查询.尝试这样的事情:
$(document).ready(function() {
var url = data.result.docs[i].source.enriched.url.url;
$("#send-my-url-to-django-button").click(function() {
$.ajax({
url: "/process_url_from_client",
type: "POST",
dataType: "json",
data: {
url: url,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success : function(json) {
alert("Successfully sent the URL to Django");
},
error : function(xhr,errmsg,err) {
alert("Could not send URL to Django. Error: " + xhr.status + ": " + xhr.responseText);
}
});
});
});
假设您的页面上有一个这样的按钮:
Send URL to Django View
单击该按钮应将URL发送到您的Django视图.然后在Django端,您可以像这样访问网址:
def process_url_from_client(request):
url = request.POST.get('url')