0
In my localhost
my app works fine, but when I do deploy
in the heroku
it does not show uploads of my. pdf files
MODEL.PY
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Client(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
protocol = models.CharField(max_length=15, null=True)
name = models.CharField(max_length=50, null=True)
number = models.CharField(max_length=18, null=True)
phone = models.CharField(max_length=10, null=True)
active = models.BooleanField(default=True)
pdf = models.FileField(upload_to='pdfs')
def __str__(self):
return str(self.id)
VIEW.PY
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from .models import Client
URLS.PY
from django.contrib import admin
from django.urls import path
from base import views
from django.contrib.auth import views as auth_views
from django.contrib.staticfiles.urls import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import settings
urlpatterns = [
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('', auth_views.LoginView.as_view()),
path('main/', views.main),
path('admin/', admin.site.urls),
]
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
@login_required
def main(request):
client = Client.objects.filter(active=True, user=request.user)
return render(request, 'main.html', {'client': client})
def logout(request):
return redirect(request, 'registration/login.html')
TEMPLATE
{% extends "body.html"%}
{% block content %}
<div class="card-columns">
{% for c in client %}
<div class="card border-primary mt-3 ; ml-2" style="width: 30rem; height: 700px">
<div class="card-header text-white bg-primary border-primary" style="font-size: 30px; text-align: center">DADOS</div>
<div class="card-body ">
<h2 class="card-title text-primary">CNPJ/CPF:</h2>
<p class="card-text" style="font-size:30px">{{ c.number }}</p>
<h2 class="card-title text-primary">RAZÃO/NOME:</h2>
<p class="card-text " style="font-size:30px">{{ c.name }}</p>
<h2 class="card-title text-primary">PROTOCOLO :</h2>
<p class="card-text" style="font-size:30px">{{ c.protocol }}</p>
<h2 class="card-title text-primary text-primary">CONTATO:</h2>
<p class="card-text" style="font-size:30px">{{ c.phone }}</p>
</div>
</div>
<div class="card-columns ">
<div class="card border-primary mt-3" style="width: auto; height: 700px">
<div class="center ">
<iframe height="690" src="{{ c.pdf.url }}" width="800"></iframe>
</div>
</div>
</div>
{% endfor %}
</div>
Did you make makemigrations and "migrate" in Heroku? Every time you change a model, you should do it. Another thing to pay attention to production, is with respect to the 'collectstatic'.
– Vinicius Bussola
yes, I think the version of Django needs to be made external with Storage cloud like Amazon S3.
– Francelmo
in production on my local machine wheel perfect. the problem happens that when I step up to Heroku does not show the uploads files. the other fields show legal.
– Francelmo
What are these 'upload files'? Aren’t you using different databases for your location and on Heroku? It may be that these upload files are only in your local bank..
– Vinicius Bussola