I am newbie in a django framework. And trying to print PDF from the submitted data through HTML form. For that I have 2 stages.
- Fillup the form
- Preview(result) those filled up data
- Generate PDF from the preview(result) page
I have managed to post data using HTML form.
My views.py
def preview(request):
if request.method == "POST":
formvals = Formdata()
formvals.date = request.POST["date"]
formvals.name = request.POST["name"]
return render(request, "result.html", {'formvals':formvals})
def getpdfPage(request):
formvals = preview(request)
print(formvals.date)
print(formvals.name)
data = {'date':formvals.date, 'formvals.name'}
template = get_template("pdf_page.html")
data_print = template.render(data)
response = BytesIO()
pdfPage = pisa.pisaDocument(BytesIO(data_print.encode("UTF-8")),response)
if not pdfPage.err:
return HttpResponse(response.getvalue(),content_type="application/pdf")
else:
return HttpResponse("Error faced")
Urls.py
urlpatterns = [
path('',views.home, name='home'),
path('getpdfPage',views.getpdfPage, name='getpdfpage'),
path('preview',views.preview, name='preview')
]
Here I get None values when i try to print data dict in getpdfPage()
Is there any way to access the data of preview() in getpdfPage().
Thanks in advance