1
Hello, I have a system in Django/python very simple to manage sweepstakes, and last xhtml2pdf to generate reports in pdf, when ultilizo it locally it works perfectly did the deploy in python Anywhere the whole system works normal except the view that generates the pdf with the data!! use of Django 3.1 I put this question in the stack a few minutes ago and was rejected due to lack of details, I am beginner, detailed questions require a more professional level. if you help me I try to show my problem!
THAT’S THE VIEW CODE
def render_pdf_view(request):
hoje = date.today()
dias = ('Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado', 'Domingo')
hj = dias[hoje.weekday()]
hora_agora = datetime.now()
hora = hora_agora.strftime('%H:%M')
acertivos = Escolha.objects.filter(sorteado=True).count()
pessoa = Pessoa.objects.all()
template_path = 'pdf_template/invoice.html'
context = {
'hj':hj,
'hora':hora,
'hoje':hoje,
'pessoa': pessoa,
'acertivos':acertivos,
}
# Create a Django response object, and specify content_type as pdf
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="{}.pdf"'.format(hoje)
# find the template and render it.
template = get_template(template_path)
html = template.render(context)
# create a pdf
pisa_status = pisa.CreatePDF(
html, dest=response )
# if error then show some funy view
if pisa_status.err:
return HttpResponse('We had some errors <pre>' + html + '</pre>')
return response
If I may, how can I do this directly on the server?
– Tharlles Té
what ports are you running the service on? and what server are you using?
– Pedro Mariz
I only created the application that basically manage draw numbers, nothing special, but I want to generate reports in pdf, so I have this view that then takes the model data(name, id, hits and etc) and play everything in a pdf, but the port I use locally is the standard of Django :8000 so I just climbed it to python.
– Tharlles Té
I’ve updated the answer, try this
– Pedro Mariz
should I run python Manage.... on python bash Anywhere? sorry if I’m being ignorant but the door is not set automatically so I make the deploy? This pdf generating scheme works perfectly in the local environment!
– Tharlles Té
yes I know it works all locally , but sometimes when trying to implement things do not go as we expect. Your error is not due to code, but where it is implemented. By trying to change the doors where your program is running, you may resolve the issue, but another solution [link] (https://www.pythonanywhere.com/forums/topic/3485/) as described in this forum , python Anywhere , uses a proxy to filter records ,( for non-paying users), and may be blocked there
– Pedro Mariz
show dude, I will follow what the link you sent me asks to do! thank you so much for the help!! quaso certo posto aqui!!
– Tharlles Té
If it works just upvote my comment for people with the same problem see the solution
– Pedro Mariz