title: How to access a variable outside of function in Django
body: <p>How would I access myvar outside of the page function. I am able to print myvar when I have print(myvar) inside the page function, but not when it is outside.</p>
  
  <pre><code>def page(request):
      form = MyForm(request.POST or None)
  
      if form.is_valid():
          instance = form.save(commit=False)
  
          myvar = form.cleaned_data.get("myvar")
          # myvar is printed here
          print(myvar)
          if not myvar:
              myvar = "this"
          instance.myvar= myvar
          instance.save()
      context = {
          "form" : form
      }
      return render(request, "home.html", context)
  
  # I want to print the contents of myvar but it doesn't work here
  print(myvar)
  </code></pre>
  
  <p>Thanks</p>