亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我需要在哪里傳遞請求?

我需要在哪里傳遞請求?

MM們 2023-09-19 14:28:42
當我單擊該按鈕時,我試圖激活一個功能,將數據傳輸到模板并打開它。這是按鈕點擊功能: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.pyurl (r '^ create_order /', CreateOrder),views.pydef 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 ()函數中傳遞請求或者如何以不同的方式正確地執行它?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

問題出在 urls.py 中

url (r '^ create_order /', CreateOrder),

這將CreateOrder (amount, request):在第一個參數的位置調用所發出的請求(不是任何數字amountrequest

您需要更改urls.pyamount以在/之后有一個額外的參數

from django.urls import path

path(r '^ create_order /<int:amount>', CreateOrder), #takes a number after the slash

然后,這將分別正確地調用作為參數amountrequest傳遞的函數。

編輯:第一個參數必須request不是amount,所以你必須將其更改為

def CreateOrder (request,amount):


查看完整回答
反對 回復 2023-09-19
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號