title: How do I get a files absolute path after being uploaded in Django?
body: <p>I want to upload a file to my database and after it is uploaded import it and eventually export the data into my database. I have the uploading working just fine but I'm not sure how to get the absolute path of the file after it is uploaded. I'm able to print out the name of the document, but if the same document name is uploaded it is appended but still shows the original file name if I call <code>form.cleaned_data['document'].name</code>. What can I do to get the absolute file path and then call a function to start processing this file?</p>
  
  <p>So this is what I'm looking to do:</p>
  
  <ul>
  <li>User uploads a .csv file</li>
  <li>File gets saved in db (with a description and file path. File path is getting stored properly in db)</li>
  <li>Get file location of file that was just uploaded</li>
  <li>Start to process this file to convert the .csv data and store in database</li>
  </ul>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  class Document(models.Model):
      description = models.CharField(max_length=255, blank=True)
      document = models.FileField(upload_to='documents/')
      uploaded_at = models.DateTimeField(auto_now_add=True)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render, redirect
  from django.views import View
  # Create your views here.
  
  from .forms import DocumentForm
  from .models import Document   
  
  class  FileUpload(View):
      def post(self, request):
          form = DocumentForm(request.POST, request.FILES)
          if form.is_valid():
              print()
              print(form.cleaned_data['document'].name)
              form.save()
              return redirect('main_db_model:home')
          else:
              return render(request, 'file_upload_form.html', {
                  'form': form
              })
  
      def get(self, request):
          form = DocumentForm()
          return render(request, 'file_upload_form.html', {
              'form': form
          })
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  from .models import Document
  
  class DocumentForm(forms.ModelForm):
      class Meta:
          model = Document
          fields = ('description', 'document', )
  </code></pre>
  
  <p>file_upload_form.html (template):</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
    &lt;form method="post" enctype="multipart/form-data"&gt;
      {% csrf_token %}
      {{ form.as_p }}
      &lt;button type="submit"&gt;Upload&lt;/button&gt;
    &lt;/form&gt;
        {% if saved %}
           &lt;strong&gt;Your profile was saved.&lt;/strong&gt;
        {% endif %}
    This is the form page
    &lt;p&gt;&lt;a href="{% url 'main_db_model:home' %}"&gt;Return to home&lt;/a&gt;&lt;/p&gt;
  
      &lt;p&gt;Uploaded files:&lt;/p&gt;
        &lt;ul&gt;
          {% for obj in documents %}
            &lt;li&gt;
              &lt;a href="{{ obj.document.url }}"&gt;{{ obj.document.name }}&lt;/a&gt;
              &lt;small&gt;(Uploaded at: {{ obj.uploaded_at }})&lt;/small&gt;
              {{ obj.document.url }}
            &lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;
  {% endblock %}
  </code></pre>