title: Using Flask with apscheduler
body: <p>I using Python Flask to along with apscheduler and trying to add/remove jobs as follows:</p>
  
  <pre><code>sched = Scheduler()
  sched.start()
  print "Schedular Started"
  
  
  def new_job():
      @sched.interval_schedule(seconds=2)
      def job_function():
          print "Hello World"
  
  
  @app.route('/add')
  def add():
      new_job()
      return 'started'
  </code></pre>
  
  <p>This bit works as expected. However, when I try to remove the job, like shown here:</p>
  
  <pre><code>@app.route('/remove')
  def remove():
      sched.unschedule_job(job_function.job)
      return "Removed"
  </code></pre>
  
  <p>I'm getting a </p>
  
  <blockquote>
    <p>NameError: global name 'job_function' is not defined" as expected. </p>
  </blockquote>
  
  <p>My question is how can I remove a job using a different route?</p>
  
  <p>Regards.</p>