<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><a href="http://anvil.works/">http://anvil.works/</a> is a pretty interesting approach to Python web applications.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 30, 2018 at 2:05 PM, kirby urner <span dir="ltr"><<a href="mailto:kirby.urner@gmail.com" target="_blank">kirby.urner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">Hi Aivar --<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">I think it's a fine idea to write simple Python scripts that write HTML files, which you may then pull up in the browser.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">There's no need to put a server behind static web pages. So, for example, I'll have my students write a page of bookmarks:<br><br># -*- coding: utf-8 -*-<br>"""<br>Created on Wed Nov 4 18:02:30 2015<br><br>@author: Kirby Urner<br>"""<br><br># tuple of tuples<br>bookmarks = (<br> ("Anaconda.org", "<a href="http://anaconda.org" target="_blank">http://anaconda.org</a>"),<br> ("Python.org", "<a href="http://python.org" target="_blank">http://python.org</a>"),<br> ("Python Docs", "<a href="https://docs.python.org/3/" target="_blank">https://docs.python.org/3/</a>"),<br> ("Spaghetti Code", "<a href="http://c2.com/cgi/wiki?SpaghettiCode" target="_blank">http://c2.com/cgi/wiki?<wbr>SpaghettiCode</a>"),<br> ("Structured Programming", "<a href="http://c2.com/cgi/wiki?StructuredProgramming" target="_blank">http://c2.com/cgi/wiki?<wbr>StructuredProgramming</a>"),<br> ("Map of Languages", "<a href="http://archive.oreilly.com/pub/a/oreilly//news/languageposter_0504.html" target="_blank">http://archive.oreilly.com/<wbr>pub/a/oreilly//news/<wbr>languageposter_0504.html</a>"),<br> ("XKCD", "<a href="http://xkcd.com" target="_blank">http://xkcd.com</a>"),<br> )<br><br>page = '''\<br><!DOCTYPE HTML><br>{}<br>'''<br><br>html = """\<br><HTML><br><HEAD><br><TITLE>Bookmarks for Python</TITLE><br></HEAD><br><BODY><br><H3>Bookmarks</H3><br><BR /><br><UL><br>{}<br></UL><br></BODY><br></HTML><br>""".lower()<br><br>the_body = ""<br>for place, url in bookmarks:<br> the_body += "<li><a href='{}'>{}</a></li>\n".<wbr>format(url, place)<br><br>webpage = open("links.html", "w")<br>print(page.format(html.format(<wbr>the_body)), file=webpage)<br>webpage.close()<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">All you need add to your example is using print() to save to a file, so the browser has something to open.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">I would not call this a "web app" yet it's instructive in showing how Python can write HTML files.<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:large">Kirby<br><br><br></div></font></span></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Mar 28, 2018 at 12:18 AM, Aivar Annamaa <span dir="ltr"><<a href="mailto:aivar.annamaa@ut.ee" target="_blank">aivar.annamaa@ut.ee</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hi!</p>
Let's say my students are able to write programs like this:
<blockquote><tt>name = input("name")<br>
<br>
if name == "Pete":<br>
greeting = "Hi"<br>
else:<br>
greeting = "Hello!"<br>
<br>
print(f"""<br>
<html><br>
<body><br>
{greeting} {name}!<br>
</body><br>
</html><br>
""")</tt></blockquote>
<p>I'd like to allow them start writing web-apps without introducing
functions first (most web-frameworks require functions).</p>
<p>It occurred to me that it's not hard to create a wrapper, which
presents this code as a web-app (<tt>input</tt> would be patched
to look up GET or POST parameters with given name).</p>
<p>This approach would allow simple debugging of the code on local
machine and no extra libraries are required in this phase.<br>
</p>
<p>Any opinions on this? Has this been tried before? <br>
</p>
<p>best regards,<br>
Aivar<br>
</p>
</div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org" target="_blank">Edu-sig@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edu-sig" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/edu-sig</a><br>
<br></span></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org">Edu-sig@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/edu-sig" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/edu-sig</a><br>
<br></blockquote></div><br></div>