Python‎ > ‎pyramid‎ > ‎

pyramid.config

http://www.adilwaseem.com/

The Response returns the union of frozenset x, y. 
from pyramid.response import Response

def frozenset1(request):
    x=frozenset({7,9,11,13})
    y=frozenset({5,10,15})
    z=frozenset.union(x,y)
    z=str(z)
    return Response('The union of frozenset is:' + z)
        
if __name__ == '__main__':
    config = Configurator()
    config.add_route('set', '/')
    config.add_view(frozenset1, route_name='set')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 1050, app)
    server.serve_forever()






The pyramid.response return with Response after getting string value from the for loop.
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    response=Response()
    for link in range(1,100):
        response.text="Hi there. "*link
    return response

if __name__ == '__main__':
    config = Configurator()
    config.add_route('hello', '/')
    config.add_view(hello_world, route_name='hello')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6500, app)
    server.serve_forever()






The pyramid returns with the requests after finding the number of 'a' in www.pythonlake.com.
from wsgiref.simple_server import make_server
from pyramid.response import Response
import requests

def find(request):
    r=requests.get('http://www.pythonlake.com')
    text=r.text
    f=text.find('a')
    f=str(f)
    response = Response()
    response.text=f
    return response
    
if __name__ == '__main__':
    config = Configurator()
    config.add_route('find', '/')
    config.add_view(find, route_name='find')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6500, app)
    server.serve_forever()






The pyramid returns with the if statement execution after testing equation of the values of two variable. 

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def test(request):
    x=range(1,0)
    y=13
    if y in x:
        return Response('y is in x')
    else:
        return Response('y is not in x')

def main():
    config = Configurator()
    config.add_route('index', '/')                        
    config.add_view(test, route_name='index')
    app = config.make_wsgi_app()
    return app

if __name__ == '__main__':
    app = main()
    server = make_server('0.0.0.0', 1000, app)
    print ('Starting up server on http://localhost:1000')
    server.serve_forever()





The html code are integrated inside the pyramid.response.Response().
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def html(request):
    return Response(
        '<a href="http://www.pythonlake.com/">Python Lake</a>'
        '<hr>'
        '<a href="http://www.pythonlake.com/aboutus">About us</a>'
        '<hr>'
        '<a href="http://www.pythonlake.com/appointment">Appointment</a>'
        '<hr>'
        '<a href="http://www.pythonlake.com/contactus">Contact us</a>')
    
if __name__ == '__main__':
    config = Configurator()
    config.add_route('links', '/')
    config.add_view(html, route_name='links')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 1000, app)
    server.serve_forever()





Equality test run through the pyramid web framework.
 
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def test(request):
    x=pow(3,10)
    y=13
    if x.__gt__(y):
        return Response('x is greater than y.')
    else:
        return Response('x is not greater than y.')

def main():
    config = Configurator()
    config.add_route('index', '/')                        
    config.add_view(test, route_name='index')
    app = config.make_wsgi_app()
    return app

if __name__ == '__main__':
    app = main()
    server = make_server('0.0.0.0', 1000, app)
    print ('Starting up server on http://localhost:1000')
    server.serve_forever()






The FileResponse returns with png file from disk.
from paste.httpserver import serve
from pyramid.view import view_config
from pyramid.config import Configurator
from pyramid.response import FileResponse

@view_config(route_name='png')
def turtle(file):
    view = FileResponse(
        'turtle.png',
        request=file,
        content_type='image/png'
        )
    return view

if __name__ == '__main__':
    config = Configurator()
    config.add_route('png', '/')
    config.scan('__main__')
    serve(config.make_wsgi_app())






Comments