I have a webapp with the following code, which is supposed to serve up any .html file I have stored in the htmls/ directory, provided the two parameters urlhash and predictiontag are correct.
import web
urls = (
'/htmlview/(.*)', 'htmlview'
)
class htmlview:
def GET(self, urlhash, predictiontag):
cache_dir = os.path.join("htmls\\", urlhash)
htmlpath = os.path.join(cache_dir, predictiontag + ".html")
with open(htmlpath, "r", encoding="utf-8") as f:
data = f.read()
return data
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
I don't know how to format the GET request from a browser window in order to actually access these files. I tried http://localhost:8080/htmlview/a?urlhash=6355865449554195623&predictiontag=Primary but it gave me the error:
<class 'TypeError'> at /htmlview/a
GET() missing 1 required positional argument: 'predictiontag'
For reference, here is the other post I was following: How to serve file in webpy?
I use flask but I am guessing that webpy wants you to specify multiple groups in the url matching pattern. (.*) probably matches the whole query string as a single argument to the GET function. Maybe you can use something like
urls = ('/htmlview/(.*)&(.*)', 'htmlview')Again, just guessing.