Weasypring-django __init__() takes 1 positional argument but 3 were given
I am facing problems trying to generate pdf from my django views using weasyprint-django
views.py
def schoolSequenceReportpdf(request,slug,pk,seq):
host=request.META['HTTP_HOST']
if request.user.is_authenticated:
skoll = None
valuecheck = None
admin_check = False
statistics = None
if request.user.is_school:
#Calling the check school profile obj.
skoll,valuecheck = check_for_skolProfile(request.user)
# Calling the check accademic year object.
accademic_yearObj,acc_valuecheck= check_for_accademicYear(skoll)
else:
try:
valuecheck= True
skoll= schoolProfile.objects.get(slug=slug)
accademic_yearObj,acc_valuecheck= check_for_accademicYear(skoll)
admin_check = adminCheck(request.user,skoll)
if admin_check is False:
return redirect('main:wrongpage')
except:
return redirect('main:wrongpage')
if accademic_yearObj:
#get classroom instance
try:
classroomobj = Level.objects.get(id=pk)
sequence = Sequence.objects.get(id=seq)
term = sequence.term
except:
term = None
classroomobj = None
else:
term = None
classroomobj = None
sequence_report_cards = FinalTermReport.objects.filter(sequence=sequence,classroom=classroomobj).order_by("-studentavg")
statistics = ClassroomResultStatistics.objects.filter(sequence=sequence,classlevel=classroomobj,seqstate=True).order_by("-created")
terms = Term.objects.filter(year=accademic_yearObj)
sequences = Sequence.objects.filter(year=accademic_yearObj).order_by('-created')
color = ReportCardColor.objects.filter(skoll=skoll)
if color:
color= color.first
filling_session = FillMarksDateScheduling.objects.filter(year=accademic_yearObj,skoll=skoll,active=True,delete=False)
context = {'color':color,'host':host,'statistics':statistics,'sequence_report_cards':sequence_report_cards,'sequence':sequence,'term':term,'filling_session':filling_session,'sequences':sequences,'statistics':statistics,'terms':terms,'admin_check':admin_check,'classroomobj':classroomobj,'name':classroomobj.name,'accademic_yearObj':accademic_yearObj,'accyear':acc_valuecheck,'skollobj':skoll,'valuecheck':valuecheck}
html_string = render_to_string("main/sequencereportcardpdf.html", context)
pdf = HTML(string=html_string).write_pdf()
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = f'attachment; filename="{classroomobj.name}.pdf"'
return response
urls.py
url(r'^sequence/report/pdf/(?P<slug>[\w-]+)/(?P<pk>[0-9]+)/(?P<seq>[0-9]+)$',views.schoolSequenceReportpdf,name="sequencereportpdf"),
I have tried changing errors i got
File "/mnt/e/digolearnsms/smsdigo/main/views.py", line 4460, in schoolSequenceReportpdf
pdf = HTML(string=html_string).write_pdf()
File "/mnt/e/digolearnsms/myenvubuntu/lib/python3.8/site-packages/weasyprint/__init__.py", line 259, in write_pdf
self.render(font_config, counter_style, **options)
File "/mnt/e/digolearnsms/myenvubuntu/lib/python3.8/site-packages/weasyprint/document.py", line 390, in write_pdf
pdf = generate_pdf(self, target, zoom, **options)
File "/mnt/e/digolearnsms/myenvubuntu/lib/python3.8/site-packages/weasyprint/pdf/__init__.py", line 127, in generate_pdf
pdf = pydyf.PDF((version or '1.7'), identifier)
TypeError: __init__() takes 1 positional argument but 3 were given
https://github.com/Kozea/WeasyPrint/issues/2205 The issue on GitHub is similar to this question, and they have had a commit to solve it. Hope you find it helpful.