Upload and view PDF's Django admin

1

I want to ask a question, I'm trying to upload a PDF file, in django, and I wanted to know if you how do I view this pdf, I have the following code:

models.py

class Edital(models.Model):
    # ...

class DataFile(models.Model):
    Arquivo = models.FileField()

    def chage_view(self):
        return self.Arquivo

class Meta:
    verbose_name_plural = 'Editais'

Numero = models.CharField(primary_key=True, max_length= 15) 
pro_reitoria = models.ForeignKey('Pro_reitoria', default="")
Arquivo = models.FileField(upload_to= "", default="")

def __str__(self):
    return self.Numero

settings.py

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

In my admin, so the file

WhenIclickontheloadedfile,PagenotFound(404)

How do I get the PDF to view? Thank you for helping me!

    
asked by anonymous 08.02.2017 / 06:39

1 answer

1

I think the only thing missing is whether you enable Django to serve static and media files, which it does not do by default. To do this, just do this on your urls.py of the project:

from django.conf.urls.static import static

# depois das suas definições de urls

if settings.DEBUG:
urlpatterns += static(
    settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(
    settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    
08.02.2017 / 20:56