views:

423

answers:

4

The last framework, which I used, was Django. I enjoy a lot of things in that, like:

  • The project structure is simple - there are not too many directories and files
  • The admin interface
  • Great documentation
  • XML export-import
  • The concept of Form objects: after you define a form, you can display the form in 1 line, you can even make a form from a database row (from an orm definition). [added on 30/12/2009]
  • i18n [added on 31/12/2009]

But there are some limitations:

  • as of december 2009 no model validation
  • the templating system is only good as far as you don't need custom template tags
    • the idea to separate the design from the logic seemed good, it is frustrating, that I cannot sum n numbers in the view [edited on 30/12/2009]
    • the template language is not designer friendly
    • the stack trace of an ex in a custom template tag is useless (if used with python 2.6). There is a patch for it, but it will go into django just in 1.2
  • django's orm (to connect to legacy systems)
    • cannot handle blob fields
    • cannot handle multi-column pk fields

Is there another web framework which has the good points of django, and does not have the listed limitations? Or is it possible to solve some problems in django?

ps: I will update the list based on the answers. I am sure there are more aspects to discuss...


I am free to use a framework in any other language, as long as I can install the stuff on a linux server


+1  A: 

Hi, try Ruby on Rails. Although sometimes you have to write some more lines of code, you can customize it easier.

And the limitations you mentioned don't exist in Rails.

I've been using it for years and was able to do anything I wanted.

Michael W.
Ah, missed an important pro of django, which rails does not have: it has form objects, and can display a predefined form object in template. Not to mention ModelForm, which makes a form from a new or existing database row.
pihentagy
http://github.com/justinfrench/formtastic
Sam Saffron
+11  A: 

Not trying to defend Django (that is not my job! :-)) just trying to give you some pointers on your list of limitations...

as of december 2009 no model validation

What exactly do you mean by this? Validation is available at the form level... And you can always override the save() method to implement whatever logic you desire and stop the save operation... Can you give an example of a scenario?

the templating system is only good as far as you don't need custom template tags the idea to separate the design from the logic seemed good, it is frustrating, that I cannot sum 2 numbers in the view

Add two numbers?

That said, you are not married to Django's templating system. You can use, for instance, Jinja2.

the template language is not designer friendly

Uhhh... Why? Most designers I worked with had no problem working with template languages way more complex than Django's... Could you give an example of what you see as unfriendly? Maybe there is a work-around.

the stack trace of an ex in a custom template tag is useless (if used with python 2.6). There is a patch for it, but it will go into django just in 1.2

I haven't experienced this stack trace issue you discuss. You can always install the patch until Django 1.2 is around though. So it seems you have a solution available.

django's orm (to connect to legacy systems) cannot handle blob fields

If you are dealing with the need to store files in the database, maybe you should look at the django-storages' DatabaseStorage.

cannot handle multi-column pk fields

This, alongside with multiple database support, are the areas of real need of improvement - I agree.

I suppose you could not use models (just straight SQL) for models that have the multi-column pk requirement (yes, it would kill the admin, but it is doable). Frankly - I don't have that problem in my models because I prefer surrogate primary keys - if a legacy model is on my way, I add a surrogate primary key to it - all the legacy code should continue to work and Django will be happy. But I do have complete control over the database tables, which might not be your case.

Multi-column primary keys are medium priority for the 1.2 release.

Multidb is high priority for 1.2 release.

The 1.2 release is expected by March 2010. Sure, the date is not written in stone.

Given my experience with other frameworks, I would rather work around my issues and stick to Django.

celopes
re: "Validation is available at the form level...", well, but as you might know, models aren't always constructed via forms. It would've been great if it was possible to actually perform validation in model's `save` method or fields' `to_python` methods. In fact, there is/was a "model validation" branch that did just that. I am not sure about its fate though (whether or not it is going to be merged into trunk for 1.2)
shylent
I really don't see the advantage of having validation at the model level. I can't conjure a scenario where you would not benefit from using django forms. If it is user interaction that is creating the model, using the form makes complete sense (to me). If it is a programmatic interaction (i.e. no user interaction involved) that is creating the model, why would you need validation? As I said - it might be me being myopic on what are the scenarios. And if I ever needed to have some validation at the model - why not override the save method and do what I must?
celopes
Well, of course you can just raise ValidationError anywhere, but surely there is little point in that, unless it is "blessed" by the framework's specification (like you are supposed to raise ValidationError in `clean`, `clean_*` and similar methods in forms, right?). My point is that validation is there to make sure, that unwanted data doesn't hit the database. As things are now, you can just initialize a model's instance with whatever values, call `save` and, _bam!_, there you have absolutely out of context data in your database.
shylent
It would be inefficient and duplicate code to validate the model again at the `save()` method. If you want to validate your data, use a form. That's where validation is supposed to occur. Django, like Python, figures you're an adult and won't stick stupid stuff in the database behind the scenes. If you're having validation problems, perhaps you should look at how you structure your data flow. You shouldn't have to re-validate it all over the place with one-off code.
Paul McMillan
@Paul: In fact, if I remember correctly, the django model-validation branch performs validation in case of ModelForms *only* in the model. The `ValidationError` s propagate then to the form's `clean()` or whatever method and get handled in a usual way (like render the form with the errors struct populated). So where is the inefficency then? Please check your sources. Also, initializing the model with out-of-context values and then saving it is not doing something *behind the scenes*, you (as a user of the model's code) simply have no way to know which values are expected ahead of time.
shylent
*And you can always override the save() method to implement whatever logic you desire and stop the save operation...*No, not always. Think of a ModelForm, which should inherit the model validations.So think of 1 model, and many forms based on it. In that case you should put the validation to model level to follow DRY.
pihentagy
*Add two numbers?* Ok, add n numbers: say I have to display a list of items, and want to know the total amount of them.
pihentagy
*That said, you are not married to Django's templating system. You can use, for instance, Jinja2.* Well, but what about i18n then?
pihentagy
**the template language is not designer friendly** : you cannot view the template in a browser, and see the final result. You cannot design the layout with WYSIWYG html editor.
pihentagy
+5  A: 

While you can to some extent swap out the bits of Django you don't like, other frameworks make it easier to do so than Django.

Assuming you want to stick with Python, the next best alternative would be Pylons. You have SQLAlchemy + Formencode for validation; Mako/Jinja/Genshi all offer a more flexible alternative to Django templates.

Another option is roll-your-own with an "anti-framework" or toolkit of libraries for WSGI handling, data mapping etc. My favourite bag of tricks is Werkzeug + SQLAlchemy + Jinja2 but really whatever fits your needs and programming style.

A word of caution is that Pylons and more DIY frameworks require a better understanding of Python than Django for even trivial projects. That's not a bad thing : however I would recommend Python newbies to get their feet wet with Django first, as it has better documentation and fewer rough edges than the other alternatives. Once you are more confident then do look around, because Django, as you have discovered, is not always the best tool for the job.

zeemonkee
+3  A: 

The reason I'm still using django, even though there's a huge number of other rough areas, is because of the most basic, core feature to the framework, the request/response dispatch system. The killer feature is the urlresolvers.reverse() function. This means that any time you need to compute a link, you can do so robustly, without concern that any change you make elsewhere in the framework won't break any computed links. Although there may be a comparable capability for frameworks in other languages, there sure doesn't seem to be anything quite as polished as django's dispatch system for python, and for the frameworks in other languages I've tried, It certainly seems to be the exception, rather than the rule. I will continue to use django for this alone, even when I'm using something else for ORM, Templates, Form processing, serialization, scaffolding or just about any other feature.

TokenMacGuy