Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
How to access MEDIA_ROOT files within the view

How to i get the file (where all the uploaded images are held when a user uploads an image), contained in the MEDIA_ROOT. I want to delete this file when the user deletes their account and all the uploaded images within it.

def function(request):
    user_file = user_file_object
    if request.method == 'POST':
    # deletes the user file
       user_file.delete()
       user.delete()
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I am sure you have defined MEDIA_URL in your settings.py file. Something like this.

MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
MEDIA_URL = '/media/'

To access the MEDIA_URL in your view use below code.

from django.conf import settings

def my_view(request):
    media_url = settings.MEDIA_URL
    path_to_user_folder = media_url + "/user_name/"
    # delete the folder.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!