title: Django sendfile download -- Page not found
body: <p>I'm using the Django sendfile module to serve files to the user. Docs:</p>
  
  <p><a href="https://github.com/johnsensible/django-sendfile" rel="nofollow">https://github.com/johnsensible/django-sendfile</a></p>
  
  <p>I used the simple backend. More precisely, I put <code>SENDFILE_BACKEND = 'sendfile.backends.simple'</code> in my <code>settings.py</code>.</p>
  
  <p>I have checked and doucle-checked that the files are there. This is my code (I think only the request function is relevant but I'm including the whole function because I use <code>pk</code> in <code>urls.py</code>):</p>
  
  <pre><code>def permit(request, pk)
      if int(request.user.id) == int(pk) and int(request.user.id) &gt;= 1:
          return sendfile(request, request.path)
      else:
          return render_to_response('forbidden.html')
      return HttpResponseRedirect('/notendur/list')
  </code></pre>
  
  <p><code>user</code> is a Django <code>User</code> object. <code>pk</code> is the regular expression taken from <code>urls.py</code>.
  And the error I get is</p>
  
  <pre><code>404: [path to file] does not exist.
  </code></pre>
  
  <p>This is the relevant entry in <code>project/urls.py</code>:</p>
  
  <pre><code>url(r'^media/uploads/(?P&lt;pk&gt;[^/]+)', 'notendur.views.permit')
  </code></pre>
  
  <p>As you can see, the <code>urls.py</code> redirects the user to the <code>permit</code> function if the regx matches. If the user's ID is equal to the directory name (I name the directories by user ID) then the user is allowed to download the file, otherwise not.</p>
  
  <p>I have confirmed that this error is due to the sendfile module because the download works fine if I serve the file directly, without the sendfile module.</p>