Search code examples
djangodjango-storage

Django get filename without url


I get a file with this commannd:

src = request.POST.get('src', '')

But the output is: https://url.com/path/filename.jpg

How can I just get path/filename.jpg?

regards Christopher


Solution

  • Yes I wrote a 3 lines command, one line would be better:

    from urllib.parse import urlparse
    import os    
    
    url = request.POST.get('src', '')
    filepath = urlparse(url).path
    src = path + (os.path.basename(filepath))