API Reference
- flask_weasyprint.make_flask_url_dispatcher()
Return a URL dispatcher based on the current request context.
You generally don’t need to call this directly.
The request context is used when the dispatcher is first created but not afterwards. It is not required after this function has returned.
Dispatch to the context’s app URLs below the context’s root URL. If the application has a
SERVER_NAME
configuration, also accept URLs that have that domain name or a subdomain thereof.
- flask_weasyprint.make_url_fetcher(dispatcher=None, next_fetcher=weasyprint.default_url_fetcher)
Return an function suitable as a
url_fetcher
in WeasyPrint.You generally don’t need to call this directly.
If
dispatcher
is not provided,make_flask_url_dispatcher()
is called to get one. This requires a request context.Otherwise, it must be a callable that takes a URL and returns either
None
or a(wsgi_callable, base_url, path)
tuple. ForNone
,next_fetcher
is used. (By default, fetch normally over the network.) For a tuple the request is made at the WSGI level.wsgi_callable
must be a Flask application or another WSGI callable.base_url
is the root URL for the application whilepath
is the path within the application.Typically
base_url + path
is equivalent to the passed URL.
- flask_weasyprint.HTML(guess=None, **kwargs)
Like
weasyprint.HTML
but:make_url_fetcher()
is used to create anurl_fetcher
If
guess
is not a file object, it is a URL relative to the current request context. This means that you can just pass a result fromflask.url_for()
.If
string
is passed,base_url
defaults to the current request’s URL.
This requires a Flask request context.
- flask_weasyprint.CSS(guess=None, **kwargs)
Like
weasyprint.CSS
but:make_url_fetcher()
is used to create anurl_fetcher
If
guess
is not a file object, it is a URL relative to the current request context. This means that you can just pass a result fromflask.url_for()
.If
string
is passed,base_url
defaults to the current request’s URL.
This requires a Flask request context.
- flask_weasyprint.render_pdf(html, stylesheets=None, download_filename=None, automatic_download=True, **options)
Render a PDF to a response with the correct
Content-Type
header.- Parameters:
html – Either a
weasyprint.HTML
object or a URL to be passed toflask_weasyprint.HTML()
. The latter case requires a request context.stylesheets (list) – A list of user stylesheets, passed to
weasyprint.HTML.write_pdf()
.download_filename (str) – If provided, the
Content-Disposition
header is set so that most web browser will show the “Save as…” dialog with the value as the default filename.**options –
Named properties given to
weasyprint.HTML.write_pdf
.automatic_download (bool) – If
True
, the browser will automatic download file.
- Returns:
a
flask.Response
object.