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 8355275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:48:50+00:00 2026-06-09T09:48:50+00:00

I have a File model, which store path field – path in the filesystem

  • 0

I have a File model, which store path field – path in the filesystem to file. All files are stored in MEDIA_ROOT/files

In template I want generate download link for File object. What is the best way to do this? Should I use static file handling in django?

TIA!

UPD

File model

class File(models.Model):
    item = models.ForeignKey(Item)
    file = models.FileField(upload_to = os.path.join(MEDIA_ROOT,'items'))
    format = models.CharField(max_length = 255)

In item’s View I do the following:

files = File.objects.filter(item_id = id)

and the pass files to the template

in template I use files.1.file.url for example and still have bad url like site.com/home/dizpers/...

UPD2

Related question

Solution

My problem was in File model, in file field. In upload_to parameter I use absolute path, but must use relative path:

file = models.FileField(upload_to = 'items')

  • 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-09T09:48:52+00:00Added an answer on June 9, 2026 at 9:48 am

    I’m not sure what exactly you mean by “generate download link”, but to simply link to the file, just use {{ some_file.url }} as your href.

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

Sidebar

Related Questions

i have an entity-model file (edmx) file which contains few tables and few stored
I have a YML file containing fixtures for a Rails model (Comment) which looks
I have a form which binds a model and a file upload using the
I have Course's model and the course consist of several file (stored only link
We have a locally-developed triple store based on b-trees which I want to use
I have some model classes which I wanted to store with the CoreData framework.
I have an upload function in an MVC 3 project which store the files
I have this dictionary in my apps model file: TYPE_DICT = ( (1, Shopping
I have these a coffeescript file for a model entree that just instanciates a
I have an effect file in XNA4, being compiled as Shader Model 3. This

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.