[英]Why can't my Django view receive data from a created tag in my Django template?
Django view: Django视图:
if request.method == 'POST':
myData = request.POST.get('tester', None)
print myData
Django template (jquery and javascript): Django模板(jquery和javascript):
var i = document.createElement('input');
i.setAttribute('type', 'hidden');
i.setAttribute('id', 'tester');
i.setAttribute('name','tester');
i.setAttribute('value', 'PLEASE GET THIS!');
$('#tester').appendTo('body');
$('#add_here').before(i);
I have no issue getting the value from an tag that is hardcoded into the template file but I am having a problem getting the value from an tag that I have created using jQuery and javascript. 我从硬编码到模板文件的标记中获取值没有问题,但是从使用jQuery和javascript创建的标记中获取值却有问题。 Any hints?
有什么提示吗?
Thank you in advance! 先感谢您!
I have discovered the issue. 我发现了问题。 There was a random closing /div tag in my HTML that didn't have an opening tag.
我的HTML中有一个随机的/ div标签,没有开始标签。 I removed it and the code started working like it should.
我删除了它,代码开始按预期工作。 For reasons unknown to me, the random /div wasn't allowing the created elements to appear in the POST data.
由于我不知道的原因,随机/ div不允许所创建的元素出现在POST数据中。 The elements were showing up in the right places when I did the inspect element, but when you look at the actual POST data the elements were not there.
当我执行inspect元素时,这些元素显示在正确的位置,但是当您查看实际的POST数据时,这些元素并不在那里。
I hope this saves someone the time it cost me. 我希望这可以节省别人花费我的时间。 Here are some links to help you validate your HTML.
这里有一些链接可以帮助您验证HTML。 These are the links I used to discover my problem.
这些是我用来发现问题的链接。
http://www.freeformatter.com/html-validator.html http://www.freeformatter.com/html-validator.html
http://validator.w3.org/#validate_by_input http://validator.w3.org/#validate_by_input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.