当我单击该按钮时,我试图激活一个功能,将数据传输到模板并打开它。这是按钮点击功能:
function openForm () {
const amount = select.value;
$ .ajax ({
url: '/ create_order /',
type: 'get',
data: {'amount': amount},
dataType: "json",
xhrFields: {withCredentials: true},
success: function (data) {
if (data ['content']) {
$ ('body'). append (data ['content']);
console.log (data ['content'])
}
},
});
}
urls.py
url (r '^ create_order /', CreateOrder),
views.py
def CreateOrder (amount, request):
count = amount.GET.dict ()
content = mark_safe (render_to_string (
'form.html',
{
'amount': count ['amount'],
},
request))
问题出在请求参数上。我在最后一行需要它,所以我需要将它传递给 CreateOrder 函数。但这就是错误发生的方式
TypeError at / create_order / ↵CreateOrder () missing 1 required positional argument: 'request'
告诉我如何在openForm ()函数中传递请求或者如何以不同的方式正确地执行它?
噜噜哒
相关分类