Я довольно новичок в django и изо всех сил пытаюсь сделать что-то очень простое. Я работаю над проектом извлечения данных в формате PDF на основе django. В этом проекте я беру счет PDF от пользователя, а затем извлекаю поля, такие как эмитент, invoice_number , дата, сумма, валюта и др., а затем сохраните эти данные в базе данных. Все работает нормально, но единственное, что я хочу - это распечатать извлеченные данные в html полях ввода форм. Ребята, не могли бы вы помочь мне
это поток
входной файл invoice.pdf -> кнопка извлечения -> печать значений в полях ввода html формы -> отправить
после извлечения PDF, я получил этот словарь
{'issuer': 'Freefiber', 'amount': 29.99, 'date': '02/07/2015', 'invoice_number': '562044387', 'currency': 'EUR', 'other': {'amount_untaxed': 24.99, 'date_due': '02/08/2015', 'vat': 'FR60421938861', 'line_number': 'FO10479674', 'client_id': '10577874', 'desc': 'Invoice from Free'}}
ожидаемый результат
вот мой код
views.py
from django.shortcuts import render, redirect, HttpResponse
from .models import InvoiceList
import os
from .forms import browse
from .models import handle_uploaded_file
from invoice2data import extract_data
# Create your views here.
def index(request):
invoices = InvoiceList.objects.all()
context = {
'invoices': invoices,
}
return (render(request, 'index.html', context))
def create(request):
print(request.POST)
issuer = request.GET['issuer']
invoice_number = request.GET['invoice_number']
date = request.GET['date']
amount = request.GET['amount']
currency = request.GET['currency']
other = request.GET['other']
invoice_details = InvoiceList(issuer=issuer, invoice_number=invoice_number, date=date,amount=amount,currency=currency,other=other)
invoice_details.save()
return redirect('/')
file_list = os.listdir("extraction/static/upload")
def add_invoice(request):
result = None
form = None
if request.method == 'POST':
form = browse(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file']) # store file in upload folder
path = "pdfextractor/static/upload/"+ str(request.FILES['file'])#path of selected file
result1 = extract_data(path) # extract data from invoice pdf file
listl=['issuer','invoice_number','date','amount','currency']
new_in_dict={}
c={}
for key in result1:
if key in listl:
new_in_dict[key]=result1[key]
else:
c[key]=result1[key]
new_in_dict['other']=c
result = new_in_dict # this is final dictionary
else:
form = browse()
context = {"form": form, "result": result}
return render(request,'add_invoice.html', context)
#return render(request, 'add_invoice.html')
def delete(request, id):
invoices = InvoiceList.objects.get(pk=id)
invoices.delete()
return redirect('/')
def edit(request, id):
invoices = InvoiceList.objects.get(pk=id)
context = {
'invoices': invoices
}
return render(request, 'edit.html', context)
def update(request, id):
invoices = InvoiceList.objects.get(pk=id)
invoices.issuer = request.GET['issuer']
invoices.invoice_number = request.GET['invoice_number']
invoices.date = request.GET['date']
invoices.amount = request.GET['amount']
invoices.currency = request.GET['currency']
invoices.other = request.GET['other']
invoices.save()
return redirect('/')
add_invoice. html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>
<body>
<div class="small_div">
<div class="container">
<br>
<h2>Invoices List</h2>
<hr>
<form action="/create">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" name="extract" value="extract"/>
<br>
<label class="form-group" for="issuer">issuer: </label>
<input class="form-control" type="text" name="issuer"><br>
<label class="form-group" for="invoice_number">invoice_number: </label>
<input class="form-control" type="text" name="invoice_number"><br>
<label class="form-group" for="date">date: </label>
<input class="form-control" type="text" name="date"><br>
<label class="form-group" for="amount">amount: </label>
<input class="form-control" type="text" name="amount"><br>
<label class="form-group" for="currency">currency: </label>
<input class="form-control" type="text" name="currency"><br>
<label class="form-group" for="other">other: </label>
<input class="form-control" type="text" name="other"><br>
<input class="btn btn-success" type="submit" value="save">
</form>
<br>
</div>
</div>
</body>
</html>