Skip to content

Instantly share code, notes, and snippets.

@cjbarnes18
Created March 21, 2012 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjbarnes18/2152918 to your computer and use it in GitHub Desktop.
Save cjbarnes18/2152918 to your computer and use it in GitHub Desktop.
open a url remotely using Pyramid
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