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_NAMEconfiguration, 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_fetcherin WeasyPrint.You generally don’t need to call this directly.
If
dispatcheris 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
Noneor a(wsgi_callable, base_url, path)tuple. ForNone,next_fetcheris used. (By default, fetch normally over the network.) For a tuple the request is made at the WSGI level.wsgi_callablemust be a Flask application or another WSGI callable.base_urlis the root URL for the application whilepathis the path within the application.Typically
base_url + pathis equivalent to the passed URL.
- flask_weasyprint.HTML(guess=None, **kwargs)
Like
weasyprint.HTMLbut:make_url_fetcher()is used to create anurl_fetcherIf
guessis 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
stringis passed,base_urldefaults to the current request’s URL.
This requires a Flask request context.
- flask_weasyprint.CSS(guess=None, **kwargs)
Like
weasyprint.CSSbut:make_url_fetcher()is used to create anurl_fetcherIf
guessis 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
stringis passed,base_urldefaults 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-Typeheader.- Parameters:
html – Either a
weasyprint.HTMLobject 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-Dispositionheader 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.Responseobject.