Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:47:52+00:00 2026-06-17T23:47:52+00:00

django 1.4. I am trying to develop a function to deploy download. I didnt

  • 0

django 1.4. I am trying to develop a function to deploy download. I didnt get the right result. I attach my code at below. When I download after click hyperlink, I got a 0 bytes file. The Content-Length is 0 in debug mode. I have read many related questions, I got some clues, but still confused, since I got 0 bytes file after download. can anyone help modify codes below, thx for ur time.

   def download_file(request, filepath, filename):
        path_to_file = filepath+"\\"+filename
        serverfile = file(path_to_file, 'rb')
        response = HttpResponse(mimetype='application/force-download')
        response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(filename)
        response['Content-Length'] = serverfile.tell()
    return response
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:47:53+00:00Added an answer on June 17, 2026 at 11:47 pm

    .tell() gives the current position in a file. Since you haven’t read any of the file, your current position will be at position 0.

    You could use os.stat(path_to_file).st_size to give the file size in bytes. Note that you should also use os.path.join(filepath, filename) to get the full (OS-independent) path to the file, rather than concatenating manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to develop a friends module to get more aquainted with django. Now
I am trying develop a basic referrer system to my Django website, system will
I am trying to develop a website with Django following various guides, the documentation
I am new to Django, MySQL, and EC2. I am trying to develop a
I am new to Django and was trying this code in a tutorial. But
i'm fairly new to django and just trying a couple simple experiments to get
I'm trying to develop a Django application with relation to exercises per workout. I
I'm trying to develop an app using Django 1.1 on Webfaction. I'd like to
I'm starting to develop a facebook application using Django. I'm trying to choose the
I am trying to develop an sample project in Django and getting errors when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.