Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda