Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django向Python发送HTML表_Python_Django - Fatal编程技术网

Django向Python发送HTML表

Django向Python发送HTML表,python,django,Python,Django,大家好 我正在使用Django,我有一个很大的疑问,我有3个HTML表,我需要将这些数据保存在mysql中,该表由用户填写,我不确定如何将这些表发送到python 我尝试过使用Ajax,但实际上我不知道如何使用它 来自我的3个表之一的HTML代码: custom.html <table id="idTable" name="table" class="table table-striped table-bordered"> <thead> <tr> <t

大家好

我正在使用Django,我有一个很大的疑问,我有3个HTML表,我需要将这些数据保存在mysql中,该表由用户填写,我不确定如何将这些表发送到python

我尝试过使用Ajax,但实际上我不知道如何使用它

来自我的3个表之一的HTML代码:

custom.html

<table id="idTable" name="table" class="table table-striped table-bordered">
<thead>
<tr>
<th>FIRST</th>
<th>Second</th>
   <tr>
</thead>
<tbody>
</tbody>
</table>
<button class="btn btn-primary" onclick="ajaxFunction()" id="IDButton">Touch me!</button>
我不知道为什么这个函数不起作用

我只想找到一个办法, 我会很高兴的!!!!
谢谢大家!

您需要使用AJAX吗?我认为作为一个初学者,最好的出发点是HTML表单。可能的重复基于重复似乎可以使用
$解决问题。获取
。哦,天哪,HTTP\u X\u请求了\u解决了我的问题,我需要使用特殊标题,这家伙如何解释识别函数“is\u ajax()”,我可以继续使用javascript代码var pokemon=[“Charmander”,“Bulbasaur”,“Squirtle”]data:{'pokemon':pokemon},函数(data){console.log(data)}请求中的python代码。is_ajax():datos=request.GET.getlist('pokemon[])返回HttpResponse(datos)控制台结果(charmanderbulbasaurstle)非常感谢,我可以继续我的项目!!!!
<script type="text/javascript">
function ajaxFunction(){
var request = $.ajax({
url: window.location.href,
type: 'get',
data: {data1: "hello"},
contentType: 'application/json; charset=utf-8'
});
request.done(function(data)){
console.log("works")
});
</script>
def custom(request, op_id):
     if request.method == "GET":
          IF request.is_ajax():
                 message ="Yes"
          else:
                 message="No"
     return render(request, "custom.html")