Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
# prints lines from a file in reverse order
def printlines(filepath):
rawdata = open(filepath).read()
lines = rawdata.splitlines()
lines.reverse()
for line in lines:
print line
<!-- blogpost.html -->
<html>
<body>
<div>${post.title}</div>
<div>${post.body}</div>
<p>And the message is: ${message}</p>
</body>
</html>
# models.py
class BlogPost(Base):
id = Column(Integer, 'id')
title = Column(Unicode(100), 'title')
body = Column(UnicodeText(), 'body')
def __init__(self, title, body):
self.title = title
self.body = body
@classmethod
def getpost(cls, title):
post = Session.query(cls).filter(cls.title==title).first()
return post
# Now your view can look up blog posts
@view_config(renderer='blogpost.html', route_name='blogpost')
def displaypost(request):
title = request.matchdict['post_title']
post = BlogPost.getpost(title)
message = 'hi there'
return {'post': post, 'message': message }
Hello, World!
from paste.httpserver import serve
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello world!')
if __name__ == '__main__':
config = Configurator()
config.add_view(hello_world)
app = config.make_wsgi_app()
serve(app, host='0.0.0.0')
~/myapp/__init__.py
~/myapp/models.py
~/myapp/views.py
~/myapp/templates/
~/myapp/static/
~/myapp/__init__.py
~/myapp/models/__init__.py
~/myapp/models/security.py
~/myapp/models/blog.py
~/myapp/views.py
~/myapp/routes.py
~/myapp/templates/
~/myapp/static/
from myapp.models import Users
from pyramid.security import authenticated_userid
@view_config(renderer='mytemplate.html', route_name='sayhello')
def welcome(request):
userid = authenticated_userid(request)
user = Users.retrieve(userid)
return {'name': user.name}
/myblog/{post_title}
/data/{author}/bio
config.add_route('blogpost', '/myblog/{post_title}')
@view_config(renderer='blogpost.html',
route_name='blogpost')
def myfunction(request):
...
<html>
<body>
Welcome back, ${name}!
</body>
</html>
<html>
<body>
Welcome back, Arthur!
</body>
</html>