from waitress import serve
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
@view_config(name='works')
def works(request):
form = """
<html>
<form action="/works" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="token"/>
<input type="file" name="profile_picture" value=""/><br/>
<input type="submit" value="save picture"/>
</form>
</html>
"""
if request.method == 'GET':
return Response(form, content_type='text/html')
else:
picture = repr(request.POST['profile_picture'])
return Response(picture, content_type='text/plain')
@view_config(name='broken')
def broken(request):
form = """
<html>
<form action="/broken" method="POST" enctype="multipart/form-data">
<input type="file" name="profile_picture" value=""/><br/>
<input type="hidden" name="csrf_token" value="token"/>
<input type="submit" value="save picture"/>
</form>
</html>
"""
if request.method == 'GET':
return Response(form, content_type='text/html')
else:
picture = repr(request.POST['profile_picture'])
return Response(picture, content_type='text/plain')
if __name__ == '__main__':
config = Configurator()
config.scan('__main__')
serve(config.make_wsgi_app())
"pserve" is just a wrapper script; the actual server being run depends
the [server] section in your configuration file.
- C