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

153
Views
Cómo acceder a los archivos MEDIA_ROOT dentro de la vista

Cómo obtengo el archivo (donde se guardan todas las imágenes cargadas cuando un usuario carga una imagen), contenido en MEDIA_ROOT. Quiero eliminar este archivo cuando el usuario elimine su cuenta y todas las imágenes cargadas dentro de ella.

 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

Estoy seguro de que ha definido MEDIA_URL en su archivo settings.py . Algo como esto.

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

Para acceder a MEDIA_URL en su vista, use el siguiente código.

 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!