Ich bin relativ neu in Python und Django,django Typeerror: get() bekam mehrere Werte für die Keyword-Argument 'invoice_id'
ich habe folgende Rest api Ansicht,
class InvoiceDownloadApiView(RetrieveAPIView):
"""
This API view will retrieve and send Terms and Condition file for download
"""
permission_classes = (IsAuthenticated,)
def get(self, invoice_id, *args, **kwargs):
if self.request.user.is_authenticated():
try:
invoice = InvoiceService(user=self.request.user, organization=self.request.organization).invoice_download(
invoice_id=invoice_id)
except ObjectDoesNotExist as e:
return Response(e.message, status=status.HTTP_404_NOT_FOUND)
if invoice:
response = HttpResponse(
invoice, content_type='application/pdf')
response['Content-Disposition'] = 'inline; filename={0}'.format(
invoice.name.split('/')[-1])
response['X-Sendfile'] = smart_str(invoice)
return response
else:
return Response({"data": "Empty File"}, status=status.HTTP_400_BAD_REQUEST)
mit folgenden Urls,
urlpatterns = [
url(r'^invoice/(?P<invoice_id>[0-9]+)/download/$', views.InvoiceDownloadApiView.as_view()),
]
root URL-Muster ist, wie folgend,
url(r'^api/payments/', include('payments.rest_api.urls', namespace="payments")),
, wenn ich den Endpunkt nennen,
localhost:8000/api/payments/invoice/2/download/
es die folgenden Fehler auftreten,
TypeError at /api/payments/invoice/2/download/
get() got multiple values for keyword argument 'invoice_id'
es nicht herausfinden kann, was diesen Fehler tatsächlich verursacht
wi Mit dieser Rechnungsnummer habe ich nur eine Rechnung in meiner Datenbank. – RTan
Fügen Sie bitte die Implementierung der Methode 'rechnungs_download' hinzu, damit wir Ihnen helfen können. – AKS
@AKS Nein, das heißt überhaupt nicht. Das wäre ein MultipleObjectsReturned-Fehler. –