简体   繁体   English

方法反向django错误

[英]method reverse django error

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. 我的错误:反向'shopping.views.payment_confirmation',参数'(35,)'和关键字参数'{}'未找到。

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/ 错误在这里payment.submit(settings.SITE_URL + reverse(“shopping.views.payment_confirmation”,args = [payment.id]))我',使用这个api https://bitbucket.org/leonardosantos/django-pagseguro2 /

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. 这一行:reverse(“shopping.views.payment_confirmation”,args = [payment.id])告诉Django在购物应用程序的views.py文件中找到一个名为payment_confirmation的方法,该文件将接受付款ID参数。

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. 在您共享的错误中,payment.id为35.错误是说您的shopping.views中没有名为payment_confirmation的方法,或者该方法不接受单个int作为参数。

You didn't share a payment_confirmation method in your views file so it seems that that is the issue. 您没有在视图文件中共享payment_confirmation方法,因此这似乎是问题所在。 You need to add: 你需要添加:

def payment_confirmation(payment_id):
 #do stuff

to your views. 对你的看法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM