Created
March 21, 2012 21:17
-
-
Save cjbarnes18/2152918 to your computer and use it in GitHub Desktop.
open a url remotely using Pyramid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wsgiref.simple_server import make_server | |
from pyramid.config import Configurator | |
from pyramid.response import Response | |
import webbrowser | |
def open_url(request): | |
if request.POST: | |
webbrowser.open(request.POST['url']) | |
form = ''' | |
<form action='#' method='POST'> | |
<label>URL:</label> | |
<input type='text' name='url'> | |
<input type='submit'> | |
</form> | |
''' | |
return Response(form) | |
if __name__ == '__main__': | |
config = Configurator() | |
config.add_route('url', '/url') | |
config.add_view(open_url, route_name='url') | |
app = config.make_wsgi_app() | |
server = make_server('0.0.0.0', 8080, app) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment