weasyprintによって生成されたpdfファイルを、たとえば " my_project/pdf_files/ "フォルダーなど、指定したフォルダーにする必要があります。
注: プロジェクトに django フレームワークを使用しています。そして、これがプロジェクトの構造です。
my_project/
----pdf_generator_app/
--------admin.py
--------models.py
--------views.py
pdf_files/
現在、views.pyにこれがあります
def generate(student_id):
student = get_object_or_404(Student, application_id=student_id)
html = render_to_string('contract.html', {'student': student})
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename="some_file.pdf"'
weasyprint.HTML(string=html).write_pdf('myfile.pdf',
presentational_hints=True,
stylesheets=[weasyprint.CSS(settings.STATIC_ROOT + '/css/styles.css')])
return response
ただし、このビューはpdfファイルをディレクトリに保存しません。ブラウザにファイルを表示するだけです。ディレクトリmy_project/pdf_files/にファイルを保存する必要があります