title: Django- Exception Type: KeyError
body: <p>I'm working on an application where I'm using the Twitter account URL of a user who logs in into my application using Twitter login to scrap the total tweet count and number of followers using <code>BeautifulSoup</code> and <code>urllib2</code>.</p>
  
  <p>views.py</p>
  
  <pre><code>import urllib2
  from bs4 import BeautifulSoup
  
  def fillform(request):
      if request.method == 'POST':
          profile = ['Tweets', 'Followers']
          followers = ''
          tweets = ''
          form = EvangelizedForm(request.POST)
          if form.is_valid():
              obj = form.save(commit=True)
              link = obj.twitter_url
              dic = {}
              r = urllib2.urlopen(link)
              src = r.read()
              res = BeautifulSoup(src)
              for p, d in zip(profile, res.find_all('span', { 'data-is-compact': "true"})):
                  dic[p] = d
              followers = dic['Followers']
              tweets = dic['Tweets']  
              obj.twitter_followers = followers
              obj.total_tweets = tweets
              obj.save()
              return index(request)
          else:
              form.errors
      else:
          #form = EvangelizedForm()
          if request.user.is_authenticated():
              form = EvangelizedForm(initial={'first_name': request.user.first_name,
                                                  'twitter_url': 'https://www.twitter.com/' + request.user.username,
                                                      'last_name': request.user.last_name})
          else:
              form = EvangelizedForm()    
  
      context = RequestContext(request,
                             {'request': request,
                              'user': request.user, 'form':form})    
  
      #return render(request, 'rango/fillform.html', {'form': form, 'context_instance':context})  
      return render_to_response('rango/fillform.html',
                               context_instance=context)
  </code></pre>
  
  <p>However, this is the error I'm encountering on a POST request:</p>
  
  <pre><code>Traceback:
  File "C:\PYTHON27\lib\site-packages\django\core\handlers\base.py" in get_response
    111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\Django\GetEvangelized\rango\views.py" in fillform
    30.             followers = dic['Followers']  
  
  Exception Type: KeyError at /rango/fillform/
  Exception Value: 'Followers'
  </code></pre>
  
  <p>I have tried running my scraping script locally and the keys <code>Followers</code> and <code>Tweets</code> do return values stored in the dictionary. What seems to be going wrong in my view? Am I importing the <code>BeautifulSoup</code> and <code>urllib2</code> modules in Django the wrong way? Or is it something else that's wrong in my approach? </p>