0

我正在尝试使用 django request.post 调用 API,但收到错误 405 'Method Not Allowed (POST)' urls: path('ciu_consume/<str:br>/<int:qty>/', CiuConsumeView.as_view()) view:

class CiuConsumeView(APIView):
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)

    def get(self, request, br, qty):
        import pdb;pdb.set_trace()
        Response = requests.put('http://inv****.***.***.c***y.in/**/**/***/***/',
                                data={'br': br, 'qty': 1})

        return HttpResponse('Success')

在这我收到错误 404

如果不是'def get()'我调用'def post',那么我也会得到同样的错误。真的卡在这上面了。对此的任何帮助都会有所帮助。

 <form id="form" method="post">{% csrf_token %}

    <table class="table table-hover" id="table_id" class="display display nowrap">
        <thead>
            <tr>
                <th>S. No.</th>
                <th>barcode</th>
                <th>product name</th>
                <th>SKU</th>
                <th>Quantity</th>
                <th>product ID</th>
                <th>Colour Code</th>
                <th>Status</th>
                <th>Mark Loss</th>



            </tr>
        </thead>
            <tbody>
            {% for in_dict in in_dict %}
                <tr>
                    <td>{{ forloop.counter }}</td>
                    <td>{{ in_dict.br }}</td>
                    <td>{{ in_dict.p_name }}</td>
                    <td>{{ in_dict.sku }}</td>
                    <td>{{ in_dict.qty }}</td>
                    <td>{{ in_dict.p_id }}</td>
                    <td>{{ in_dict.clr_code }}</td>
                    <td>{{ in_dict.status }}</td>
                    <td><input type="button" name="consume" class="btn btn-success" value="consume" onclick="window.location.href='/api/admin-apis/ciu_consume/{{ in_dict.br }}/{{ in_dict.qty }}/';"></td>
                </tr>
            {% endfor %}


            </tbody>

    </table>
    </form>
4

1 回答 1

-1

尝试在链接前添加“https://”

因此,在这种情况下,例如,如果您点击链接“http://example.com”,请尝试“https://example.com”

有时,由于上游服务器的原因,请求无法正确到达 Django

于 2020-07-13T11:56:42.893 回答