title: global name 'request' is not defined
body: <p>When using the example <strong>"views.py without functions.py"</strong>, it is working <strong>fine</strong> and session is being checked alright, so it returns the username.</p>
  
  <p>But, when using the second example, <strong>with the functions.py</strong>, is showing me the following <strong>error</strong> </p>
  
  <blockquote>
    <p>NameError at /login/ </p>
    
    <p>global name 'request' is not defined</p>
  </blockquote>
  
  <p><strong>views.py without functions.py</strong></p>
  
  <pre><code>def main(request):
      c = {}
      c.update(csrf(request))
  
      if request.session.get('username'):
          susername = request.session['username']
      else:
          susername = ""
  
      return render_to_response("login/login.html",{'username': susername},context_instance=RequestContext(request))
  </code></pre>
  
  <p><strong>views.py with functions.py</strong></p>
  
  <pre><code>def main(request):
      c = {}
      c.update(csrf(request))
  
      susername = loggedin()
  
  
      return render_to_response("login/login.html",{'username': susername},context_instance=RequestContext(request))
  </code></pre>
  
  <p><strong>functions.py</strong></p>
  
  <pre><code>from django.template import RequestContext
  
  def loggedin():
      if request.session.get('username'):
          susername = request.session['username']
      else:
          susername = ""
  
      return susername
  </code></pre>
  
  <p>Why is second one not working and how can I solve it?</p>
  
  <p>Thanks</p>