Davies
Posts: 135
Joined: Sat Apr 04, 2015 4:24 pm

web.py webpage running at host location

Sat Oct 14, 2017 1:36 pm

is it possible to have web.py open its own output?
for example
python script...

Code: Select all

import web

urls = (
    '/', 'Index'
)

app = web.application(urls, globals())

render = web.template.render('static/')


class Index(object):
    def GET(self):
        msg = "Hello World"
        return render.index(msg=msg)


if __name__ == "__main__":
    app.run()
html code, running from python_file/static (create a folder called static for this to go in, file is named index.html)

Code: Select all

$def with (msg)
<!DOCTYPE html>
<html lang="en">
	<body>
        <header>
            <h1>$msg</h1>
        </header>
	</body>
</html>
to run this i currently would go to localhost:8080 on the computer it is running from, but is it possible to have the webpage opened just by running the python script? could there be a possibility where localhost wouldnt work and it would need to find its own IP?

Davies
Posts: 135
Joined: Sat Apr 04, 2015 4:24 pm

Re: web.py webpage running at host location

Sat Oct 14, 2017 2:22 pm

ive been able to use threading and webbrowser but now it opens 2 instances of the web page..

Code: Select all

import web
import threading
import webbrowser
import time


def open_web():
    time.sleep(2)
    webbrowser.open('http://localhost:8080')


t1 = threading.Thread(target=open_web)
t1.daemon = True
t1.start()

urls = (
    '/', 'Index',
)

app = web.application(urls, globals())

render = web.template.render('static/')


class Index(object):
    def GET(self):
        msg = "Hello World"
        return render.index(msg=msg)


if __name__ == "__main__":
    app.run()

Return to “Python”

Who is online

Users browsing this forum: No registered users and 15 guests