[LABI] tema05 part1 added
- Missing only the free exercise of including CSS/JS on the html static file
This commit is contained in:
parent
ca711863a7
commit
deeb5518d3
|
@ -0,0 +1,10 @@
|
|||
import cherrypy
|
||||
|
||||
|
||||
class Actions(object):
|
||||
@cherrypy.expose
|
||||
def do_login(self, username=None, password=None):
|
||||
if username is None or password is None:
|
||||
return "Preencha os campos!"
|
||||
else:
|
||||
return "Bem-vindo, %s!" % username
|
|
@ -0,0 +1,54 @@
|
|||
import os
|
||||
import cherrypy
|
||||
import Actions
|
||||
|
||||
|
||||
PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
class HTMLDocument(object):
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
with open("example1.html", "r") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
class Node(object):
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
return "Eu sou o índice do Node (Node.index)"
|
||||
|
||||
@cherrypy.expose
|
||||
def page(self):
|
||||
return "Eu sou um método do Node (Node.page)"
|
||||
|
||||
|
||||
class Root(object):
|
||||
def __init__(self):
|
||||
self.node = Node()
|
||||
self.html = HTMLDocument()
|
||||
self.actions = Actions.Actions()
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
return "Eu sou o índice do Root (Root.index)"
|
||||
|
||||
@cherrypy.expose
|
||||
def page(self):
|
||||
return "Eu sou um método do Root (Root.page)"
|
||||
|
||||
@cherrypy.expose
|
||||
def form(self):
|
||||
cherrypy.response.headers["Content-Type"] = "text/html"
|
||||
return open("form1.html")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = {
|
||||
"/": {
|
||||
"tools.staticdir.on": True,
|
||||
"tools.staticdir.dir": PATH,
|
||||
}
|
||||
}
|
||||
cherrypy.quickstart(Root(), "/", config=conf)
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import json
|
||||
import requests
|
||||
|
||||
|
||||
address = "Universidade de Aveiro, 3810-193 Aveiro, Portugal"
|
||||
|
||||
servurl = "https://nominatim.openstreetmap.org/search.php?format=json&q=%s" % address
|
||||
|
||||
r = requests.get(servurl)
|
||||
|
||||
print(json.dumps(r.json(), indent=4, sort_keys=True))
|
||||
print("Latitude:", r.json()[0]["lat"], "\nLongitude:", r.json()[0]["lon"])
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Exemplo HTML 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Exemplo HTML 1</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
import cherrypy
|
||||
|
||||
|
||||
class HelloWorld(object):
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
return "You have successfully reached " + cherrypy.request.headers["Host"]
|
||||
|
||||
|
||||
cherrypy.quickstart(HelloWorld())
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Form 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="actions/do_login" method="post">
|
||||
<p>Username</p>
|
||||
<input type="text" name="username" value="" size="15" maxlength="40"/>
|
||||
<p>Password</p>
|
||||
<input type="password" name="password" value="" size="10" maxlength="40"/>
|
||||
<p><input type="submit" value="Login"/></p>
|
||||
<p><input type="reset" value="Clear"/></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,5 @@
|
|||
import requests
|
||||
|
||||
|
||||
f = requests.get("https://www.ua.pt")
|
||||
print(f.text)
|
|
@ -0,0 +1,7 @@
|
|||
import requests
|
||||
|
||||
|
||||
url = "http://127.0.0.1:8080/form"
|
||||
data = {"username": "admin", "password": "admin"}
|
||||
f = requests.post(url, data=data)
|
||||
print(f.status_code)
|
Loading…
Reference in New Issue