Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Intro to Pylons / Pyramid

878 views

Published on

Published in: Technology
  • Be the first to comment

Intro to Pylons / Pyramid

  1. 1. http://www.pylonsproject.org
  2. 2.  Gives you some exposure to web frameworks in general and how they work. Exposes some of the magic that some frameworks like Rails do for you. It might make you better, but time will tell.
  3. 3.  Pylons was merged with repoze.bfg (http://bfg.repoze.org) Pylons is actually not in development any longer, but maintained beside Pyramid. “Only pay for what you eat” philosophy
  4. 4.  I used ‘pip’ (http://www.pip- installer.org/en/latest/) $ pip install pyramid You will also need to install SQLAlchemy $ pip install SQLAlchemy
  5. 5.  $ pcreate –s alchemy myappname
  6. 6.  See setup.py in the root of your application Installing your app $ pip install –e . Installing a forked app $ python setup.py
  7. 7.  Models for a Pyramid application are stored in a file called /models/models.py It creates a class called MyModel for you. You can delete it.class MyModel(Base): __tablename__ = models id = Column(Integer, primary_key=True) name = Column(Text, unique=True) value = Column(Integer)def __init__(self, name, value): self.name = name self.value = value
  8. 8.  Create all of your models in /models/models.py Similar to Django
  9. 9.  Routes are defined in __init__.py in the app rootconfig.add_route(blog, /blog/{id:d+}/{slug})config.add_route(blog_action, /blog/{action})config.add_route(auth, /sign/{action})
  10. 10.  You can map urls to your views using the views.py file Use @view_config() decorator for each route@view_config(route_name=home, renderer=blog:templates/index.mako)
  11. 11.  The default templating engine is Mako (http://www.makotemplates.org) Syntax % for row in row: ${makerow(row)} % endfor <% def name=“makerow(row)”> % for name in row: <p>${name}</p> % endfor </def>
  12. 12.  Addons officially endorsed: http://docs.pylonsproject.org/en/latest/docs/ pyramid.html#pyramid-add-on- documentation Add it to your setup.py file Then run $ python setup.py develop May need to pip install the add on first
  13. 13. $ git clone https://github.com/Pylons/pyramid_blogr.git$ python setup.py develop$ initialize_pyramid_blogr_db development.ini$ pserve --reload development.ini

×