I will tell you, my dear readers, about the wonderful Pylons web framework (Python language). It is not clear why he was so deprived of attention on Habré. I will try to correct this injustice. I consider it the best and I will try to reveal to you many of its charms.
Pylons was created with an eye on popular solutions, as the wiki tells us. But from personal experience I’ll tell you that the main ideas were taken from Ruby On Rails and improved!
Pylons makes extensive use of external components:
He practiced only alchemy, for this about her and examples.
We describe our model:
# user = User(name=u"") user.password = sha1("12345").hexdigest() session.add(user) # masha = session.query(User).filter_by(name=u"").first() # post = BlogPost(title=u" ", body=" ",user = masha) # post.keywords.append(Keyword(keyword='cookies')) # session.delete(masha) # , , "" tUser = User.__table__ session.execute(tUser.delete().where(tUser.c.name.like(u'A%')))
Routes is an exact replica of rail equivalent. Except for working with subdomains. Although I am sure it will appear soon in other frameworks.
Example route setup:
# map.connect("user_info", "/users/:name/info", controller="account", action="info") # submappers with map.submapper(controller="blog", path_prefix="/blog/") as blog: # regexp blog.connect(R"{id:\d+}", action="show") # REST- blog.connect("create", action="create", conditions=dict(method=["POST"])) blog.connect("update", action="update", conditions=dict(method=["PUT"]))
We use:
url_for("user_info", name="vlad") => "/users/vlad/info" url_for(controller="blog", action="show", id="5") => "/blog/5"
PS
There is nothing special to say about templates, rail philosophy - it is possible to write python code in them, although it is not worth it, but it’s convenient for tests. But the form is another thing, but it is next time.
Thanks for attention.
Source: https://habr.com/ru/post/87210/
All Articles