jquery - “str”对象没有属性“get”?
问题描述
我尝试使用 Django 表单和 ajax 更新一些数据,问题是表单不接受 'POST['dat'],我不知道为什么?任何解决方案
jQuery:
$.ajax({
headers: {
"X-CSRFToken": csrftoken
},
data: {'dat' : $('#form-one').serialize(),'id':id},
type: 'POST',
url: '/commande/update2post/',
success: function(response) {
$.ajax({
headers: {
"X-CSRFToken": csrftoken
},
});
视图.py:
def update2post(request):
if request.method == 'POST' and request.is_ajax:
print(request.POST['id'])
print(request.POST.get('id'))
commande = get_object_or_404(Commande, id=request.POST['id'])
das = request.POST['dat']
form = Commande_Form2(data=request.POST['dat'],instance=commande)// the issue ...
if form.is_valid():
form.save()
表格.py
class Commande_Form2(forms.ModelForm):
Date = forms.CharField(widget=forms.TextInput(attrs={'type': 'date'}))
Date_validation = forms.CharField(widget=forms.TextInput(attrs={'type': 'date'}))
class Meta:
model = Commande
fields = ('Date','Client','Numero_commande','Montant_HT','Montant_TVA','Montant_TTC','Type_Service','validation','Date_validation')
解决方案
推荐阅读
- drools - Drools - fire only once when a condition in child List is met
- reactjs - Using special character like Pound symbol or exclamation mark symbol (# or !) on path of React Router on ReactJS
- python-3.x - Rotating log files based on lines
- javascript - Why do arrays coerce in a specific way?
- conv-neural-network - Using Pre-trained ELMo to Generate Words embeddingE
- r - 如何用句点替换单个字母之间的空格
- html - css中的动画链接容器
- python - 如何在 Google Sheets API 中激活聚合选项
- amazon-web-services - 升级后工作节点未加入 EKS 集群
- google-maps - 如何使用意图打开谷歌地图导航并将折线作为参数而不是开始和结束位置