Move socket import, remove Request.G, and add simple hello example (#12)
* Further guard import of socket to make it optional This is so that systems without a (u)socket module can still use Microdot. For example if the transport layer is provided by a serial link. * Add simple hello.py example that serves a static HTML page
This commit is contained in:
26
examples/hello.py
Normal file
26
examples/hello.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from microdot import Microdot, Response
|
||||
|
||||
app = Microdot()
|
||||
|
||||
htmldoc = """<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Microdot Example Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1>Microdot Example Page</h1>
|
||||
<p>Hello from Microdot!</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
@app.route("", methods=["GET", "POST"])
|
||||
def serial_number(request):
|
||||
print(request.headers)
|
||||
return Response(body=htmldoc, headers={"Content-Type": "text/html"})
|
||||
|
||||
|
||||
app.run(debug=True)
|
||||
@@ -43,7 +43,10 @@ except ImportError:
|
||||
try:
|
||||
import usocket as socket
|
||||
except ImportError:
|
||||
import socket
|
||||
try:
|
||||
import socket
|
||||
except ImportError:
|
||||
socket = None
|
||||
|
||||
|
||||
def urldecode(string):
|
||||
|
||||
Reference in New Issue
Block a user