title: How to avoid getting referenced before assignment when sending list back to html page from flask app
body: <p>I am trying to get tweets using twitter api using a search word. The html form requests user to enter search word and the flask app gets it using request method and collects all the tweets from API. The problem is when i need to send tweets back to HTML page to print. I'm getting referenced before assignment error.
  Heres my flask app.</p>
  
  <pre><code>@app.route('/realtime')
  def realtime():
    tweetCount=0
    s=[]
    if request.method == 'POST':
      auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
      api = tweepy.API(auth, wait_on_rate_limit=True,
                 wait_on_rate_limit_notify=True)
      search = request.form.get('word')
      public_tweets = api.search(q=search, lang="te", count=100)
      for tweet in public_tweets:
  
                  Tweet = tweet.text
                  Tweet = re.sub('((www\.[\s]+)|(https?://[^\s]+))','URL',Tweet)
                  Tweet = re.sub('@[^\s]+','TWITTER_USER',Tweet)
                  Tweet = re.sub('[\s]+', ' ', Tweet)
                  Tweet = re.sub(r'#([^\s]+)', r'\1', Tweet)
                  Tweet = Tweet.strip('\'"')
                  a = ':)'
                  b = ':('
                  Tweet = Tweet.replace(a,'')
                  Tweet = Tweet.replace(b,'')
                  tag = 'TWITTER_USER' 
                  rt = 'RT'
                  url = 'URL'
                  Tweet = Tweet.replace(tag,'')
                  tweetCount+=1
                  if rt in Tweet:
                    continue
                  Tweet = Tweet.replace(rt,'')
                  Tweet = Tweet.replace(url,'')
                  s.append(Tweet) 
    return render_template('home.html',
                            tweets=s) 
  </code></pre>
  
  <p>Here is my html code with python blocks to print the tweets that we get from the app.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Flask Tweepy Tutorial&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;form class="form-inline" method="GET" action="{{ url_for('realtime') }}"&gt;
              &lt;input class="form-control" type="text" name="word"&gt;
              &lt;button class="btn btn-primary" type="submit"&gt;search&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;br&gt;
      &lt;div&gt;
          {% for tweet in tweets %}
          {{ tweet}}   
          {% endfor %}  
     &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there any other way to send that tweets to html page without getting referenced before assignment.</p>