Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda