Thursday, December 27, 2007

Pylons and Django

Thinking about switching the webapp portions of GameClay from Pylons to Django. This would be our third framework (web.py -> Pylons, Pylons -> Django), and Pylons is mostly doing acceptably, though it's pretty annoying in some places and needs some code to fill in functionality that Django provides for free. So this is not something I'm going to do lightly.

Here's a list of the various aspects and advantages & disadvantages of the frameworks:

Templates

For Pylons, I'd stick with the default of Mako. Django comes with its own templating language, but it's not terribly hard to swap it out. However, the existing contrib apps expect templates to be written in Django's language, so if we do any customization of contrib apps, we'll need to use Django's. It's probably better to stick with that for all web templates, even though we'll be using standalone Mako in the game compiler.

Advantages for Pylons:
  • I don't have to rewrite our existing Mako templates
  • Mako is significantly more powerful than Django, with arbitrary expressions, defs, template inheritance (beyond layouts)
  • Mako filters get pulled from the template namespace automatically, which is a useful convenience when using potentially lots of filters
  • Same template system for website and game compiler
  • I can extend it with defs, in the template, without needing to write a separate Python module to write new tags
Advantages for Django:
  • I like the syntax better; it seems cleaner and easier to remember
  • Filters can take arguments; useful for things like indent()
  • The inclusion_tag syntax provides cleaner-syntaxed and more flexible blocks of reusable content than Mako's defs. The pitfall is that these are not defined with the other templates; they live in the template_tags directory.
Models

For Pylons, I'd use our custom Diffle DB database wrapper. For Django, I'd use its ORM.

Advantages for Pylons:
  • Simpler; I know SQL already, don't need to learn a custom model definition language
  • Can handle multiple databases reasonably easily. It seems very difficult to add this to Django; there's been a branch with it since 2006, but no movement on it. It seems like it'd be a real pain to adapt save() and the query methods to a horizontally partitioned database.
  • Gives finer-grained control over queries; I can often avoid some extraneous SELECT or UPDATE statements that Django's ORM adds.
  • Supports multi-column primary keys, something I've found pretty useful in past DB models.
Advantages for Django:
  • The model definition classes are actually kinda convenient to use; would eliminate the mental context switch needed to go between SQL and Python. (I can get similar benefits by moving to SQLAlchemy + Pylons, but then I lose the other advantages of using only a thin wrapper).
  • The admin interface is very convenient; it'd let Mike respond to routine complaints from users instead of requiring my intervention. (I might be able to build something similar by introspecting the database, but it'd take time.)
Controllers
Pylons controllers are basically WSGI apps, setup by the "paster controller" script. Django controllers are functions that take a Request and return a Response. Pylons uses WSGI pretty extensively throughout; in order to understand the choices it's made for controllers, it helps to understand WSGI really well (I don't, yet).

Advantages for Pylons:
  • Each Pylons controller is its own WSGI app and in theory can use any other WSGI middleware. (In practice, I'm not sure this works, since Pylons constructs the controller objects with each request.)
  • Provides an easy way to attach data to controllers, like a database or mogile connection
  • Routes syntax is a little cleaner and more flexible than Django's URL-based dispatching.
Advantages for Django:
  • Don't have to use the ugly c, request, session, etc. global variables. Since WSGI apps have a defined signature, they can't take additional parameters, which can be quit inconvenient in Pylons.
  • Don't need to mess with StackedObjectProxies. Globals themselves aren't suitable for use in a webapp (they aren't threadsafe), so Pylons has its own version of a threadlocal. Unfortunately this is one hell of a leaky abstraction; you can't do dir() or vars() on it and get back anything sensible, and they break when used in generators.
  • More explicit. Less to keep in mind.
  • Less verbose. Controllers are just functions, and they can all live in views.py (though you can break them out into separate modules if necessary). Presumably they could be callables if necessary, though that breaks the next point.
  • Can be decorated. Django provides a bunch of useful decorators, like @login_required.
I much prefer Django's controller system - it's simple, intuitive, and doesn't have lots of boilerplate. Personally, I think that Pylons' approach of using globals is a big mistake; it was one of the main reasons I moved away from web.py

Sessions/Login/Registration
Pylons gives you AuthKit by default, but that looks so unpolished, undocumented, and unsuitable to GameClay that I'd probably have to write my own. Django offers the contrib.auth application, which depends on the Session middleware.

Advantages for Pylons:
  • Completely flexible, since I'm writing my own. Can include things like IP addresses in the session table, or reference the sessions table to see who's playing which games, or check out what your friends are playing.
  • Integrates easily with the rest of the app, eg. templates and other controllers
Advantages for Django:
  • Provides usable default controllers for login, logout, and registration
  • User objects integrated with request; no need to explicitly check for login
  • Can retrieve all sessions through Session model; however, session models have only the key and data, and so if we want to search by user or page, we have to do it ourselves. We probably need to use custom middleware for this; we can't do it as a session backend because we don't know the username at that point, and it'd be a pain to do it as an authentication backend because we'd also need to change the Session model and that's not directly accessible.
  • Handles details like tamper-proof sessions, hashing, generating unique sessions, etc. transparently
  • Has convenient @login_required decorators for marking posts that require logins. Also allows filter functions; this could be useful once we have shared games and such


Other goodies

With Pylons, you're basically on your own. You can use any Python libraries you need, but you can do that with Django too. Django provides a bunch of nifty features that we might like to use:

Advantages of Django:
  • CSRF detection. We need to add this to all our forms otherwise; this is pretty handy middleware.
  • Redirects. Particularly if we change the ID or URL scheme. We don't want to ever break URLs; this could be a handy way to avoid that.
  • Syndication feeds. There are Python libraries to do this, but the contrib app is likely easier to use


Configuration, Packaging, and Testing
Pylons is based on Paste, setuptools, and nosetests. Django has its own config and packaging system, and uses doctest and unittest for testing. The two are roughly equally easy to use - they both provide single commands to setup most things.

Advantages for Pylons:
  1. They handle multiple config files very well. Each config file is a separate .ini, so you have a test.ini for testing and a development.ini for development and a production.ini for production. Each of these can be checked in, and you specify the configuration to run when you execute Paster. Django lets you have multiple settings modules, but you have to switch between them with an environment variable or command-line switch, which is kinda annoying.[edit: the command-line switch turns out to not be that annoying in practice, though a little confusing if you don't know about it.]
  2. Searches for doctests in all locations, not just models and a specific test module. When you have lots of non-DB code, as we do, there will likely be lots of other stuff.
  3. Easy to specify foreign dependencies via setuptools, and create command-line scripts, and all the other great stuff that setuptools does. Using setuptools with Django is somewhat clumsy; I hope it's possible.
Advantages for Django:
  • Using a Python module as a config file keeps everything Pythonic, and gives some added flexibility
  • The concept of separate "sites" and "apps" results in a cool architecture where we can potentially utilize other people's contributed apps. I doubt this will be terribly relevant for us, but it may turn up something neat.
Overall, I think Pylons has the advantage for packaging and distribution. I'm disappointed that Django seems to be moving away from setuptools, even dropping it for packaging the Django distribution itself. Pylons also really thought through deployment in multiple environments, while Django seems to have done a quick & dirty solution so they could go on to other things.
Other reviews

http://pythonmag.blogspot.com/2006/02/pylons-vs-turbogears.html
http://jesusphreak.infogami.com/blog/why_django
http://jesusphreak.infogami.com/blog/vrp1
http://www.cmlenz.net/blog/2006/08/the_python_web_.html

34 comments:

Crispin Wellington said...

We have forked Django and removed the template engine and replaced it with Mako. This includes porting the entire Admin and supporting applications. Check out our project here!

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

zero said...

This phenomenomChina Wholesale is typified by mobile phonethe rise ofbusiness. Incredible range of products available with “Low Price and High Quality” not only reaches directly to their target clients worldwide but also ensures that cheap cell phones wholesale from China means margins you cannot find elsewhere and cell phonesChina Wholesale will skyroket your profits.cosplay costumes
cheap cell phones
cheap cocktail dresses
Cheap Wedding Dresses
cheap jewelry

zero said...

Tn Requin
him advice during this particular scene Nike Air Riftand advises him to attend school. jeans dieselAs the episode plays out Bubbles takes Sherrod to school and assists him to process himself into the school they visit. Chaussures puma
Or another scene in whichTn Requina young kid is found to be driving an Escalade, Air Maxwhere most of the other kids admire him, Wholesale Polo Shirtsas he acts as someone not of his age buttn requincheap nike shox simply because it is accepted into this drug world but wouldn’t necessarily work in a very clean cut type of town.

tn requin said...

sleeping bag
tablecloth
travel luggage
car gps
car parts
GPS navigation
portable GPS
lcd tv
flat tv
digital picture frames
unlocked cell phones
wedding dresses
wedding jewelry
chaussures mode
chaussures Femmes
women's shoes
round tablecloth
discount handbags
chaussures sport
chaussures pas cher
fashion bedding
id lanyard
lanyard
creative gadgets
gift ideas
kids wall stickers
wall stickers
bath curtains
kitchen faucet
bathroom faucet

shopping online said...

Adsense of Jordan Shoes : just do it!
Adsense of Moncler Jackets : sends to warm, give you more comforts of life!
Adsense of NFL Jerseys : everything is possible!
Adsense of Christian Louboutin : choice me is choice beautiful foot and body!
Adsense of Puma Shoes : champion is in the first line!
Adsense of Gucci Shoes : Allows you to enjoy the leisure life in the fun!
Adsense of Vibram Fivefingers : taste original life, wear the most morden and comfortable shoes!
Adsense of GHD Hair straighteners : why make our hair so beautiful and lots stylers, for choice me is choice happy!
Adsense of Michael Jordan Shoes : just do it!

sally21c said...

The factors you need to be aware of zigtech, the two most important is the durability and Comfort of the zigtech reebok. Paying for high price for reebok from a reputable brand is not a bad idea As They must have used better quality reebok shoes that will withstand The Elements is zigtech shoes. A well manufactured jacket Will show at Signs of Reebok Easytoneeasytone and easytone shoes should be easy to use.

happyoutlet said...

Overland Park, Kansas, Sprintchi flat iron argues that this is not the time to solve the dispute before the confirmation of March.chi flat irons For subscribers of Bloomberg yesterday's hearing can be found here.

Plan will control EchoStar Corporation, the largest secured creditor. It would replace the 97 percent stake for $ 944 million for 15 percent higher wages in kind notes guaranteed. Secured creditors

also have chi Straightening irons cheapthe right to buy 97 percent of preferred shares the right to place $ 125 million to fully support EchoStar.

said...

So many kinds of nice Christian louboutin shoes,Christian louboutin boots on our online Christian louboutin store.Discount Christian louboutin sale is wildely offered here covering complete collection of Christian louboutin evening,Christian louboutin peep toe,Christian louboutin platforms,Christian louboutin pumps,Christian louboutin sandals,Christian louboutin slingback and Christian louboutin wedges.

Wonderful Jewelry said...

fashion jewelry wholesale
wholesale fashion jewelry
china jewelry wholesale
china fashion jewelry
jewelry wholesale china
fashion jewelry china
wholesale jewelry
jewelry wholesale

Unknown said...

Nice information,Ankara escort
many thanks to the author.Ankara escort
It is incomprehensible to me nowAnkara escort
, but in general,Escort ankara bayan
the usefulness and significance is overwhelming.Ankara escort
Thanks again and good luck!
Ankara escort
became the first designer in Wimbledon's 133-year history to create official uniforms for the tournamentescort ankara
As part of this year's event, which starts next week.
will introduces the first ...Escort ankara
determinationEscort ankara
to maintain and enhance the values for which our two brands are famous throughout the world.Eskort ankara
The rugby ralph lauren brand brings to Wimbledon the look of timeless elegance,Escort ankara
drawing on our rich history and traditionsEscort ankara
expert and i like your blog and the information you have
mentioned in this post about the Google tools is really great!
Ankara Escort Bayan
Escort Bayan Ankara
escort bayan
escort
escort istanbul
Bayan Escort
escort bayan ankara
escort bayan ankara
escort ankara ilan
Escort ankara bayan
escort bayan ankara çankaya
Ankara escort bayan
Escort Bayan Ankara
Ankara Escort,
Ankara Eskort

Thanks for sharing. Very impressive

escort ankara said...

Ankara Escort,
Ankara Escort,
Ankara Escort,
Ankara Escort,
Escort Ankara,
Escort Ankara,
Escort Ankara,
Escort Ankara,
Escort Bayan Ankara,
Escort Bayan Ankara,
Escort Bayan Ankara,
Escort Bayan Ankara,
Ankara Escort,
Escort Ankara,
Escort Bayan Ankara,
Escort Ankara,
Ankara Escort,
Escort Bayan Ankara,

escort ankara said...

Escort Bayan Ankara,
Ankara Escort,
Escort Ankara,
Escort Ankara,
Ankara Escort,
Escort Bayan Ankara,
Escort Ankara,
Ankara Escort,
Escort Bayan Ankara,
Ankara Escort,
Escort Ankara,
Escort Bayan Ankara,

escort ankara said...

Ankara Escort,
Escort Bayan Ankara,
Ankara Escort,
Escort Ankara,
Escort Ankara,
Ankara Escort,
Escort Bayan Ankara,
Ankara Escort,
Escort Bayan Ankara,
Escort Ankara,
Escort Bayan Ankara,
Escort Bayan Kayseri,
Escort Kayseri,
Kayseri Escort,
Escort Ankara,

escort ankara said...

Ankara Escort,
Escort Bayan Ankara,
Ankara Escort,
Escort Ankara,
Escort Ankara,
Ankara Escort,
Escort Bayan Ankara,
Ankara Escort,
Escort Bayan Ankara,
Escort Ankara,
Escort Bayan Ankara,
Escort Bayan Kayseri,
Escort Kayseri,
Kayseri Escort,
Escort Ankara,

escort ankara said...

Ankara Escort,
Escort Ankara Bayan,
Escort Bayan Ankara,
Escort Ankara,
Escort Bayan,

London Crumpet said...

London Crumpet has a message board where London escorts and agencies can post their messages about their services or announce people about any update of their profile. Visitors can also rate the escorts on Hot or Not gallery and give some credentials to the escorts they like.

escort ankara said...

Hi, Thank you write.
to share is Escort Bayan Ankara thank you share.
good site admin

Escort Ankara
Escort Ankara
Escort Ankara
Ankara Escort
Ankara Escort
Ankara Escort
Escort Bayan Ankara
Escort Bayan Ankara
Escort Bayan Ankara
Bayan Escort
Escort Bayan
Escort Bayan
Bayan Escort
Escort Bayan
Bayan Escort
Escort İstanbul
İstanbul Escort

mr.mustafa said...

=====================================
دردشة عراقية
دردشة احساس العراق

Bayan Ankara Escort said...

Seksi Escort Ankara
Ankara Escort  seksi genç eskort kızlar için bir eskort ajansı . Escort Bayan  ajansı, Ankara'nın en güzel bayan escort en güzel erotik hizmetler sağlar.

Escort Bayan Ankara, hizmeti, sexi escort kızlar ,.


Eskort Bayanlar Ankara, eskort sevimli görünüyor ve dostu doğanın güzelliği ve cazibesi Ankara eskort kızlar, için bilinen,
kendi tutku ve sıcak eğrileri, onların güzel güneş ankara escort  kız Latin eskort pürüzsüz bir cilt öptü ...
ve en güzel fantazileri yaşatmak için bütün imkankarını zorlayacklardır.
bayan ankara escort dahil olmak üzere uygun merkezi yerlerde .

ankarada seçkin escort, Ankara eskort bayan, fotoğraf galerisi keşfetmek!

Geç Incall rezervasyon seçtiğiniz
escort ankara bayan tavsiye ederiz.
Escort Bayan Ankara,
Escort Bayan,
Ankara Escort,
Ankara Escort Bayan,
Escort Bayan Ankara,
Escort Bayan,
Escort Ankara Bayan,
Ankara Escort,
Ankara Escort Bayan,
Escort Bayan Ankara
Ankara Escort Bayan
Escort Ankara
Bayan Ankara Escort
Bursa Escort
Escort Bayan Ankara,
Escort Ankara

escort ankara said...


Hi, Thank you write.
to share is Ankara Escort thank you share.
good site admin


Escort Ankara
Ankara Escort
Escort Bayan Ankara
Escort Bayan Ankara
Ankara Escort
Escort Ankara
Escort Ankara
Escort Ankara
Escort Bayan Ankara
Escort Ankara
Escort Ankara
Escort Ankara
Escort Ankara
Ankara Escort

Unknown said...

Site's character and a great color match .. Göğüs estetiğiI will recommend your site to the other platforms.

Nam LeB said...

I use Mako for my site - softindex.info

think it's faster than django template

jay paul said...

Nice post! Can’t wait for the next one. Keep stuff like this coming.

HP - Pavilion 15.6" Laptop - 4GB Memory - 500GB Hard Drive (15-e015nr)

HP - Pavilion 17.3" Laptop - 4GB Memory - 500GB Hard Drive (17-e010us)

Frozen Juegos said...

Thanks for sharing. I hope it will be helpful for too many people that are searching for this topic.
Signature:
Jugar juego de frozen en línea gratis, los nuevos de princesa de Disney juegos frozen - la princesa encantadora y linda. Divertirse frozen!

Facebook Descargar said...

Thanks for sharing. I hope it will be helpful for too many people that are searching for this topic.
Signature:
download descargar facebook gratis para Android celular and download free descargar facebook apk and descargar facebook gratis , descarga facebook

Anh Mai said...

Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
Signature:
Versión en facebook en español descargar a los países hablan Español: facebook entrar direto agora , facebook en español para and facebook entrar direto

HaNa Chang said...

You topic is very great and useful for us…thank you.
Signature:
download baixar facebook movel, Facebook movel, baixar facebook movel. Facebook chat, baixar whatsapp gratis, fazer o download baixar whatsapp para Android, iPhone. Últimas Facebook

Whatsapp Descargar said...

Great post,Thanks for providing us this great knowledge,Keep it up.
A good blog.
Signature:
download free descargar whatsapp and download baixar whatsapp online and descargar whatsapp gratis , baixar whatsapp gratis

iniciar sesion facebook entrar said...

great post. i like it. feeling great when reading your post .
Signature:
facebook entrar iniciar sesion gratis - Sitio Oficial iniciado sesión en Facebook lengua española. facebook entrar rápido, facebook iniciar sesion en tu cuenta de entrar facebook

Trần Linh said...

All are just taking advantage of your kindness to stop his star mng hate this kind whatsapp gratis , unblockedgames very nice , free unblockedgames online to play , descargar whatsapp , unblocked games 77 , unblocked games online

Bella Tran said...

Well this a very a nice blog
----
play game juegos de terror and play game jogos online online and play game unblockedgames

general manager said...

Thanks for sharing about django,
"blueapplecourses"

sude yarenoglu said...

TURKEY ESCORTS REKLAMLARI
ankara escort,
ankara escortlar,
escort bayan ankara,
çankaya escort,
balgat escort,
çukurambar escort,
dikmen escort,
ankara vip escort,
ankara escort,
eryaman escort,
mersin escort,
adana escort,
konya escort,
samsun escort,