Hi Everyone,
I want my visitors when arrive on site to sign-in with their details then a visitor pass printed from a label printer. I am stuck at generate pdf; even though it is able to generate pdf with visitor name.
My issue is after pdf is generated it does not redirect to a different page. My understanding is you do 1 request and browser returns 1 response. Is there any work around?
I am also looking for away to print visitor pass as soon as the form.is_valid() is true.
Thanks for your help.
Views.py
def visitor_vic_signin(request):
if request.method == "POST":
form = VisitorFormVic(request.POST)
if form.is_valid():
form.save()
#print visitor tag
visitorData = form.cleaned_data
visitorName = visitorData['name']
#Create Byrtestream buffer
buf = io.BytesIO()
#Create a canvas
c = canvas.Canvas(buf, pagesize = letter, bottomup=0)
#create a text object
textob = c.beginText()
textob.setTextOrigin(inch, inch)
textob.setFont("Helvetica",14)
#add some lines of text
lines = [visitorName]
for line in lines:
textob.textLine(line)
#finished up
c.drawText(textob)
c.showPage()
c.save()
buf.seek(0)
return FileResponse(buf, as_attachment=True, filename='something.pdf')
return redirect(visitor_vic_menu)
else:
form = VisitorFormVic()
context={'form': form}
return render(request, "visitor_app/visitor_vic_signin.html",context)