我需要将weasyprint生成的pdf文件作为某个指定的文件夹,例如在文件夹“ my_project/pdf_files/ ”中
注意:我正在为我的项目使用 django 框架。这是项目的结构。
my_project/
----pdf_generator_app/
--------admin.py
--------models.py
--------views.py
pdf_files/
Run Code Online (Sandbox Code Playgroud)
目前我在我的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
Run Code Online (Sandbox Code Playgroud)
但是此视图不会将 pdf 文件存储到目录中。它只是在浏览器上显示文件。我需要将文件存储在目录my_project/pdf_files/
我正在将 postgres 与 docker 一起使用,但遇到了问题。我成功 docker-compose up --build
\n当我运行下面的命令时它工作正常。psql 按预期以 my_username 用户开头。我可以看到我的数据库,\\l,\\dt 命令工作正常。
\n\n\ndocker-compose exec db psql --username=my_username\n--dbname=my_database
\n
但是当我运行下面的命令时,我得到错误role \xe2\x80\x9cpostgres\xe2\x80\x9d does not exit,
\n另外 \\l, \\dt 不起作用,甚至psql命令也不起作用
\n\ndocker exec -it my_db_container_1 bash
\nsu-postgres
\ncreateuser --createdb --password new_user
\n
在第二种情况下我怎样才能做到正确?出了什么问题?我很困惑
\ndocker-compose.yml
\nversion: "3.9"\n\nservices:\n #### other services ####\n db:\n image: postgres:latest\n restart: always\n environment:\n POSTGRES_DB: my_database\n POSTGRES_USER: my_username\n POSTGRES_PASSWORD: my_password\n ports:\n - 5432\n volumes:\n - postgres_data:/var/lib/postgresql/data/\n\n\nvolumes:\n …Run Code Online (Sandbox Code Playgroud) 我在Employee和Manager类之间有继承.员工 - 超类,经理 - 子类.
class Employee(models.Model):
###
name = models.CharField(max_length=50, null=False)
address = models.CharField(max_length=50, null=False)
###
class Manager(Employee):
department = models.CharField(max_length=50)
###
here I don't want the 'name' and 'address' fields of Employee class.
(I want other fields of Employee and department field of this class to be stored in
Manager table in database)
###
Run Code Online (Sandbox Code Playgroud)
怎么能实现这一点.提前致谢.