是否可以在 Django 中重定向到没有 AJAX 的条带结帐页面?

Is it possible to redirect to a stripe checkout page without AJAX in Django?

我有一个 FormView,我在提交表单后做了一些事情,然后我想重定向到条带结帐。没有Javascript可以吗?

class ApplicationForm(forms.ModelForm):
    class Meta:
        model = Application
        fields = "email", "name"


    def save(self, commit=True):
        application = super().save(commit=commit)
        checkout_session = stripe.checkout.Session.create(...) # I'm creating the session here and do some other stuff with the form input
        return application

class ApplicationView(CreateView):
    template_name = "application.html"
    form_class = ApplicationForm

    def get_success_url(self):
        # TODO: How do I redirect to Stripe checkout here?

您可以为此使用重定向:

from django.shortcuts import redirect

def get_success_url(self):
    # Redirect the user to the Stripe Checkout page (i suppose that is an external url from your app)
    stripe_checkout_url = 'https://stripe/checkout/url'
    return redirect(stripe_checkout_url)
    # If it's an app url like: stripe:checkout (name 'checkout' and namespace = 'stripe')
    # return redirect('stripe:checkout')