Django for web2py developers
Asked Answered
K

5

13

Now that I've gotten relatively familiar with web2py, I'd like to give Django a go.

What are the main differences?

What would be the most efficient way to get started taking into account web2py knowledge? (It must help to have some python application framework knowledge,no?)

EDIT

Also, if you've used both, can you offer an opinion on which you prefer and why?

Kovar answered 10/12, 2009 at 2:21 Comment(1)
I believe you should first make sure you know Python. Web2py does not work as common Python code would work - the global namespace is a mess, many things are imported implicitly, it is hard to call web2py's internal code as pythonic and sometimes you hit the wall (eg, if you define db database in db.py, as suggested by tutorial, then global db variable will be accessible in models.py and eg. people.py, but not in contacts.py). Just learn to architect your code properly again, not the way web2py works, but the way Django code works.Empty
L
27

web2py was very much inspired by Django and if you know one it is easy to learn the other. We added some features we did not find in Django, including: database migrations (alter tables automatically), tickets on errors, a web based IDE, a database abstraction layer that works on Google App Engine, a role based access control mechanism with pluggable login modules.

One of the fundamental design differences is that in Django apps are implemented as modules and therefore you need to restart the server when you edit them. In web2py instead Models/Views/Controllers are not modules, they are executed (not imported) by the frameworks and therefore you do not need to restart the server when they change.

Another difference is that Django uses an ORM, web2py uses a DAL. The DAL is slightly lower level than the Django ORM and this makes it closer to the SQL syntax (for example is allows left joins, arbitrary aggregates, nested selects and combinations thereof) while remaining portable (we support 10 different databases). The DAL also make it easy to do dynamic meta-programming of models (such as create models at runtime based on specs stored in file such as an XML or CSV file).

Django has been around longer so you find more people skilled with it and more applications deployed.

Liechtenstein answered 10/12, 2009 at 19:50 Comment(4)
You don't need to restart your Django server when you change your code (djangoproject.com/weblog/2005/jul/20/autoreload). It looks like this has been true since mid 2005.Grotto
No if you use the Django server but - if I am not mistaken - you need to restart Apache if you run Django with Apache+mod_wsgi or mod_python. In web2py you do not need to restart the web server even if you do not use the built-in one.Liechtenstein
You do not need to restart Apache, you can reload mod_wsgi or fcgi.Stratification
@mdipierro: You are referring to DAL superiority over ORM. I am concerned however about the ability to add custom methods to the structures representing records in the database. Is it possible eg. to add close() method to the class / object representing single record of db.shops table? So if I have shop object representing single shop, I can invoke shop.close() and it does all the logic that in case of Django I could put inside single method associated with this specific model?Empty
M
13

Django = old

Web2py = new

Anything Django does, web2py does better. This is because web2py was made long after django and has learned from Django's mistakes, though it makes all new mistakes ;)

Main difference, and what is keeping me in web2py:

  1. Django has incredible documentation...web2py is so intuitive that it doesn't need as much...HOWEVER! I have found that the Django documentation is applicable to web2py, for the most part. If you spend a day and read the django book (Ch 1-7), you will get the idea about how that is true. So in a way, saying Django is better documented is asinine. Also, note that any framework that goes around talking about the volumes of documentation for it as a good thing...be concerned... documentation is good, not needing any to begin with = better. Web2py's existing documentation more than meets the needs of 90% of the users. The remaining 10% have to go take a look at the framework library code (not as much of it as Django, and not as scary). Also, if you get to the point where you are spending more than 30% of your time going through library code, it is time to move away from frameworks and move towards collections of libraries (such as pylons). At that point it means you are not doing anything that web frameworks were designed to handle...

  2. SQLForm in Django is TextModel. Once you create a form using TextModel (=SQLForm). Good luck trying to change the CSS of a single input field! In web2py you just do form.element(), no such thing in Django. You have to go through "widget()", but to get to widget, you have to first go through the input field type, etc...

  3. Also, manual DB migration...change schema? Sorry...have to either download and install a separate migration app (South), or have to do it manually in your DB console.

  4. Lastly, no out of the box support for multiple DBs... think hoops...

In other words... with Django... hope you like jumping and hoops.

If you want to really take a jump forward from web2py, try Pylons...seriously...

Biggest drawback of web2py is its age and smaller code base...this is not unreasonable though, considering Django is like the first python web framework to implement RAILS style RAD ideas and is like twice the age of web2py. Web2py is still in its early adopter portion of its life...Django is in the beyond critical mass part coming up to decline... web2py should reach critical mass any day now in the next 2 years, I predict.

CONCLUSION Spend a day, read the django book (ch 1-7), and read the Pylons book (Part 1), and then think about why you are using a framework to begin with. For me it was to get as much done as quickly as possible, and without looking up documentation 30% the time.

Web2py meets the above needs for me.

Methenamine answered 10/5, 2010 at 16:12 Comment(0)
C
10

I made a small in-house web app completely in Django, and then afterwards completely in web2py. It's the only way to really understand the differences and their impact upon the developer experience.

I prefer web2py because there are more conveniences built into the environment than offered by Django, but web2py is much newer than Django, and hindsight always makes it easier make new implementations better. Since web2py has guaranteed backward compatibility, it is entirely plausible that some new tool makes web2py outdated in a few years from now. That is the normal way of things.

Anyhow, they are very close to each other, far more so than any other web framework compared to either of the two. From the point-of-view of a Java-based web framework for instance, they might seem almost identical to each other.

Cyanite answered 8/5, 2010 at 22:0 Comment(2)
Good point, +1. But the real differences are clearly visible when you are trying to do something more advanced, more customized in both frameworks. I believe you are then able to see that Django is superior to Web2Py, as you are clear about what happens in your application, also all the features of Web2Py are, or could be easily implemented in Django. There are some differences, like lack of web-based IDE in Django (maybe there is a module for it), but at least Django is properly interpreted by various IDEs, and is highly customizable and stable.Empty
@Tadeck: regarding my experience with web2py, I shipped sites successfully, was very clear about what was happening in my apps, did not have to reimplement features, used web2py in an IDE just fine (PyDev Eclipse), contributed code up to trunk, experienced perfect stability (web2py guarantees forward-compatibility!), contributed to the web2py book, and generally enjoyed interaction with a friendly community. I am sure all these things are possible with Django too. Just sayin'.Cyanite
R
6

It definitely helps to have knowledge of some python framework.

Most effective way to get started would be, to compare the different sectors of the two, i.e. Model, View, Controller, Url Dispatching, Templates, Forms, etc.

Here is one great comparison of few frameworks. Am sure it'll help.

Rabbitfish answered 10/12, 2009 at 13:58 Comment(1)
The link does not work any more. Could you find the resource you were referring to and update the link? It would be great. Thanks.Empty
M
4

I was a Django programmer before settling on web2py. I found myself more efficient with web2py, possibly because of the sensible defaults (implicit imports, default views, etc) and the great support at the forum.

Mebane answered 12/12, 2009 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.