Using Python Libraries in Django

95 views
Skip to first unread message

felipe herrera

unread,
Apr 22, 2021, 1:19:45 PM4/22/21
to Django users
Hello! I would appreciate if someone could help me with a doubt I have about using Python libraries in Django. I will try to be as clear as possible so here it goes:

In my job I work with invoices that are all saved in a specific directory (PDF files). In my job I am interested in only one specific value in a row which is a number. My job is to extract that value from all the invoices and sum them all. So, I made a python script  in which I use the libraries Pandas, os and PDFplumber and it works great. In code.png, you can see the loop I use to extract the row and value that I want by using PDFplumber and then sum all these values. In invoice.png you can see how PDFplumber divides the invoice in rows in columns.

So, here is the thing: I want to deploy a Django App so that other people in the enterprise can use the python script I use ( they don't know anything about Python programming). So, I would want to deploy a Django app in which they can upload the directory with all the PDF files and then use the python script I show in code.png. But I'm having problems with the logic behind it. My questions are:

1) Can we use any python libraries in Django ( such as PDFplumber, pandas, etc) ?
2) Would I put my python script in views.py?  (Something like this) 


--------------- app/views.py------------

import os
import pdfplumber
import pandas as pd

from django.shortcuts import render

import numpy as np


def function(request):

    #Python script shown in code.png

    return render(request, 'app/response.html',{"data":data})


Thank you beforehand!




invoice.png
code.png

Kasper Laudrup

unread,
Apr 22, 2021, 3:53:36 PM4/22/21
to django...@googlegroups.com
On 22/04/2021 18.48, felipe herrera wrote:
> 1) Can we use any python libraries in Django ( such as PDFplumber,
> pandas, etc) ?

Yes.

Of course something like a Python library for rendering 3D graphics with
OpenGL wouldn't make much sense to use for a web framework, but you can
use any Python code with Django.

> 2) Would I put my python script in views.py?  (Something like this) 
>

That would probably be just fine most of the time and in this case it
looks like the simplest thing to do.

Kind regards,

Kasper Laudrup

OpenPGP_signature

felipe herrera

unread,
Apr 22, 2021, 4:46:07 PM4/22/21
to django...@googlegroups.com
Awesome! Thank you . 

Andrés 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dd418eeb-2799-c8bd-8916-8a83754bfeb5%40stacktrace.dk.

Gerardo Palazuelos Guerrero

unread,
Apr 22, 2021, 8:05:50 PM4/22/21
to django...@googlegroups.com
Have a look at the following video. It might help with your first question.

Regards,

--
Gerardo Palazuelos Guerrero



Agoua David

unread,
Apr 23, 2021, 3:47:06 AM4/23/21
to django...@googlegroups.com
Yes it's possible to use other python library, and for second question i think it's better to encapsulate tour code in a class toi create a service and call it in your  views. This a clean way and like this your Can call it in a thread if you want to savez Time.

felipe herrera

unread,
Apr 23, 2021, 5:40:28 PM4/23/21
to Django users

Great video. Thank you Sr. ! 

Gabriel Araya Garcia

unread,
Apr 23, 2021, 8:07:14 PM4/23/21
to django...@googlegroups.com
Felipe: 
Mandame una muestra del archivo el cual usaría esta pequeña aplicación de consulta, puede ser una tabla con los datos ya procesados (tú dices que con pandas está sumando correctamente) ahora lo que necesitas es la aplicación para que los demás funcionarios puedan ver los resultados ordenados y/o graficados.
Pues bien, yo puedo construirte un aprox de esta consulta en Django, para así darte una idea de cómo poder incorporar otras consultas.
Puede ser un excel o csv el que me envíes.

Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages