0

I'm calling a method using reverse but I have problem argument that I am not able to understand. My error : Reverse for 'shopping.views.payment_confirmation' with arguments '(35,)' and keyword arguments '{}' not found.

My url:

url(r'^payment_confirmation/(?P<id>\d+\d{2\})/$', 'payment_confirmation', name='payment_confirmation'),

My view:

def show(request):
    ...
    ...
    payment.submit(settings.SITE_URL + reverse("shopping.views.payment_confirmation", args=[payment.id]))

My model Payment:

class Payment(models.Model):
    ...
    ...
    def submit(self, redirect_url):
        '''
            Sends self as a Payment through PagSeguro API.
            Payment instance MUST BE SAVED before calling this method.
        '''

        if not self.id:
            #Temporary to identify which problem caused the crash.
            raise ValidationError

        #creating a reference if its None
        if self.reference is None:
            self.reference = configs.PAGSEGURO_REFERENCE_PREFIX + str(self.id)

        document = Document()
        document.appendChild(self.to_element(document, redirect_url))

        response = document2dict(api.submit_payment(document))

        try:
            self.code = response['checkout']['code']
            self.answered_on = datetime.datetime.now()
            self.save()
        except:
            error_str = ""
            if type(response["errors"]["error"]) != list:
                response["errors"]["error"] = [response["errors"]["error"]]
            for error in response["errors"]["error"]:
                error_payment = ErrorPayment()
                error_payment.code = int(error['code'])
                error_payment.payment = self
                error_payment.save()
                error_str += "[%s: %s]" % (error_payment.code,
                                           error_payment.get_code_display())
            raise Exception(error_str)

the error is here payment.submit (settings.SITE_URL + reverse ("shopping.views.payment_confirmation", args = [payment.id])) I', using this api https://bitbucket.org/leonardosantos/django-pagseguro2/

1 Answer 1

2

This line: reverse("shopping.views.payment_confirmation", args=[payment.id]) tells Django to find a url that matches a method called payment_confirmation in the views.py file in the shopping app that will accept a payment ID parameter.

In the error that you shared, the payment.id was 35. The error is saying that either there is no method called payment_confirmation in your shopping.views or the method does not accept a single int as a parameter.

You didn't share a payment_confirmation method in your views file so it seems that that is the issue. You need to add:

def payment_confirmation(payment_id):
 #do stuff

to your views.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Jeremy! I have this method in view and yet the error continues.
def payment_confirmation(request, id): return HttpResponse("aguarde o pagamento, obrigado!")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.