title: Passing Stripe Checkout ID to Django URL
body: <p>The success page, which contains the download link to download a file after completing the purchase should be accessible only after having done the payment.</p>
  <p>The idea is to pass the <code>{CHECKOUT_SESSION_ID}</code> to the success url. Only if the correct url <code>.../success/?session_id={CHECKOUT_SESSION_ID}</code> is inserted the page is accessible.</p>
  <p>How can I pass the <code>{CHECKOUT_SESSION_ID}</code> to my url?</p>
  <p>Here is my views.py file:</p>
  <pre><code>def success(request):
      return render(request, 'checkout/success.html')
  
  def index(request):
      # sendMail()
  
      try:
          checkout_session = stripe.checkout.Session.create(
              line_items = [
                  {
                      'price': 'price_1LUvcWKKYbcIekP0ZtUlCmAI',
                      'quantity': 1,
                  },
              ],
          mode = 'payment',
          success_url = 'http://127.0.0.1:8000/checkout/success' + '/?session_id={CHECKOUT_SESSION_ID}',
  
          cancel_url = 'http://127.0.0.1:8000/create/',
  
          )
  
  
      except Exception as e:
          return str(e)
  
      return redirect(checkout_session.url, code=303)
  </code></pre>
  <p>And this is my urls.py file:</p>
  <pre><code>from django.urls import path
  from checkout.views import *
  
  app_name = 'checkout'
  
  urlpatterns = [
      path('', index, name='index'),
      path('success/', success, name='success'),
  ]
  </code></pre>
  <p>This is the html file which I copied from stripe. It is called by a &quot;Pay Now&quot; button.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Buy cool new product&lt;/title&gt;
      &lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?version=3.52.1&amp;features=fetch&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://js.stripe.com/v3/&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;section&gt;
        &lt;div class=&quot;product&quot;&gt;
          &lt;img src=&quot;https://i.imgur.com/EHyR2nP.png&quot; alt=&quot;The cover of Stubborn Attachments&quot; /&gt;
          &lt;div class=&quot;description&quot;&gt;
            &lt;h3&gt;Stubborn Attachments&lt;/h3&gt;
            &lt;h5&gt;$20.00&lt;/h5&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;form action=&quot;/create-checkout-session&quot; method=&quot;POST&quot;&gt;
          &lt;button type=&quot;submit&quot; id=&quot;checkout-button&quot;&gt;Checkout&lt;/button&gt;
        &lt;/form&gt;
      &lt;/section&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>