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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:38:10+00:00 2026-05-14T06:38:10+00:00

The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File

  • 0

The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File object has no attribute ‘url’ However, django.db.models.fields.files.FieldFile extends File and does have all the attributes described in the docs for File, but I can’t create one without giving it a model field.
All I want it something that does what the docs for django.core.files.File (link above) say it does, take a python file and give it attributes like ‘url’ and ‘path’ and ‘name’, can anyone help?

Cheers, Jake

  • 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-05-14T06:38:11+00:00Added an answer on May 14, 2026 at 6:38 am

    Regardless of what the Django doc says, if you look at the code for the File class, I don’t see it there. Following Ignacio’s suggestion, you can derive from the Django File and use the MEDIA_ROOT and MEDIA_URL settings to implement the property you’re looking for…

    from django.core.files import File
    from django.conf import settings
    
    class UrlFile(File):
        def _get_url(self):
            root_name = self.name.replace(settings.MEDIA_ROOT, '')
            return '%s%s' % (settings.MEDIA_URL, root_name)
        url = property(_get_url)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be in the Django docs somewhere but I can't seem to find
I have the code form django docs , but this will output an error.
I can't see any provision for this in the django docs, so how do
The Django docs say this on the subject: Note also that Django stores signal
django's manager docs has a paragraph overwritten with DO NOT FILTER AWAY ANY RESULTS
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
I'm using the Django Redirect app ( http://docs.djangoproject.com/en/ dev/ref/contrib/redirects/) but I'd like to have
According to this section in the Django docs I should use {% blocktrans %}
I can't seem to find a solution for the following in the django docs.
To extend the User object with custom fields, the Django docs recommend using UserProfiles

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.