title: How to get a valid csrf token when using tastypie?
body: <p>I am using tastypie to create an api for my Django project. My project requires that the user logins in order to make edits to models view etc. So my first step was to login the user using tastypie by creating the login and logout functions in the UserResource as described <a href="https://stackoverflow.com/questions/11770501/how-can-i-login-to-django-using-tastypie">here</a>. The response contained a sessionid cookie that i used to logout. My resources use SessionAuthentication and DjangoAuthorization. But when i try to post or put or delete on a model using a tastypie resource url, I get an error a 401 error. Some people suggested that i must use a valid csrf_token. But how can i do that when tastypie login view won't return one.
  example code:</p>
  
  <pre><code>class EntryResource(ModelResource):
      customer = fields.ForeignKey(CustomerResourse, 'customer', full=True)
      creator = fields.ForeignKey(UserResource,'creator',null=True,full=True,blank=True)
      class Meta:
          queryset = Entry.objects.all()
          resource_name = 'entry'
          authorization = DjangoAuthorization()
          authentication = SessionAuthentication()
  </code></pre>
  
  <p>my client.py</p>
  
  <pre><code>    headers={"Content-Type":"application/json"}
      #login. I don't get a csrftoken here, but works fine which is odd because i post data r
      resp = requests.post(login_url, data=json.dumps(credentials), headers=headers)
      cookies ={'sessionid':resp.cookies['sessionid']}
  
      entry = {
          'title':'New Entry',
          'snippet':'New Snippet',
          'created': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'),
      }
      entry_json = json.dumps(entry)
      entry_add_response = requests.post(entry_api_url,data=entry_json,
                                        headers=headers,cookies=cookies)
      #entry_add_response.status_code is 401
  
      #logout works as it should
      logout_resp = requests.get(logout_url, cookies=cookies)
  </code></pre>
  
  <p>what am i doing wrong? Am I not doing the right steps?
  all my urls have ?format=json appended to them. Tried without didn't work. I also tried changing from django and session authentication and authorization to basic (Authentication(), Authorization() ). I then get a 500 error. I starting to feel a bit desperate.... </p>