Export simple Anvil form to static html?

What I’m trying to do:
I have a simple form where the only interactive element is a button that links to an url.

Is it possible to export this form to static html?

Then I could simply paste this html into my static webpage, instead of having to load the anvil app into the page via an iframe, which is slower and ‘overkill’ for this simple form.

What I’ve tried and what’s not working:
Copy + paste the source code of the form from the browser.

If I understand, instead of embedding an Anvil app inside a web page, you could:

  • In the Anvil app: create an http endpoint that returns an URL
  • In the web page: put a button and add some JavaScript code to call the http endpoint and fetch the URL calculated by the anvil app

Or you could have the http endpoint create a little snippet of HTML that includes the button and more.

I have our internal wiki, our e-commerce web site and more embedding little html snippets returned by Anvil http endpoints, so I can share info across them without much editing of those big obscure web apps.

1 Like

No simple way to do it. But hopefully, this can help you a bit (your page will likely be messed up).

Just paste this code when you are ready to capture your form

from anvil.js.window import document
html=document.documentElement.outerHTML
html='\n'.join([line for line in html.split('\n') if not line.startswith("$(function() {var anvilServicePreloadModules=[]")])
html_file=BlobMedia("text/html",html.encode(),"exported_form.html")
download(html_file)

Hopefully someone else can provide a better way of doing this.

Good idea, but unfortunately it produces the same outcome as saving the source code from the browser, see image below.

image