title: How to make an app.route() in Flask only functional if you are coming from a specific URL?
body: <p>I'm creating a project to learn how to use Stripe and work together with a registration template. My integration with Stripe is working, I can successfully make a payment and after the payment is done, I'm redirected to my registration template.</p>
  <p>The problem is, you should only get access to the registration template after going through the Stripe integration, but what is happening is anyone who access the '/register' URL manually can by pass the payment stage and register himself in the registration template.</p>
  <p>The route I'm using in the process is:</p>
  <pre><code>@app.route('/stripe_pay')
  def stripe_pay():
      session = stripe.checkout.Session.create(
          payment_method_types=['card'],
          line_items=[{
              'price': '{{ PRICE ID }}',
              'quantity': 1,
          }],
          mode='subscription',
          success_url=url_for('register', _external=True),
          cancel_url=url_for('signup', _external=True),
      )
      return {
          'checkout_session_id': session['id'],
          'checkout_public_key': app.config['STRIPE_PUBLIC_KEY'],
      }
  </code></pre>
  <p>The '/register' route performs user data collection and then writes down all the information in a database. All is working fine with the process.</p>
  <pre><code>@app.route('/register')
  def register():
      form = RegistrationForm()
      if form.validate_on_submit():
          todb = c_personal_info( first_name = form.first_name.data,
                              last_name = form.last_name.data,
                              email = form.email.data,
                              password = form.password.data,
                              subscription='M')
          with db.session.begin():
              db.session.add(todb)
          flash('Thanks for registering! You can now login!', category=&quot;success&quot;)
          return redirect(url_for('login'))
      return render_template('register.html', form = form)
  </code></pre>
  <p>The session is not authenticated, as the '/register' template is actually where you would create your credentials to log in.</p>
  <p>My question is how do I make the '/register' end point only accessible when you are coming from the '/stripe_pay' end point? I also would love to hear your ideas and different aproaches to this.</p>