DJANGO VS. WEB2PY

http://www.mengu.net/post/django-vs-web2py


Many people would like to know the differences between Django and web2py. In this short entry, I will make a comparison of two popular Python web frameworks, Django and web2py.

  • Django is an MTV framework, web2py is an MVC framework.

  • Web2py lets you focus on developing your application, Django doesn't. It wants you to do all its stuff.

  • With web2py you don't need to import anything but with Django you need to import everything that you will use. I think Django way is better here. However this is how web2py makes you focus on developing the application.

  • Web2py has no configuration or settings but Django has. Of course it is nothing compared to Java configuration files.

  • Both frameworks support backward compatibility.

  • Web2py automatically migrates your database, Django doesn't. Of course you can disable this if you wish.

  • Both frameworks support shell interacting.

  • Web2py automatically detects and renders the views but Django doesn't.

  • Web2py has two kinds of administration. One is Application Admin in where you can develop your application, the other one is Django like administration. Django has way more better administration panel than web2py with many options you can use.

  • Web2py has a better template system than Django. It is a lot permissive. No endif, endfor, endifequal, endifnotequal or {% %}. Everything goes between {{ }} and {{ pass }}. As of 1.2 Django supports smart if tags.

  • Web2py lets you use Python expressions in your views but Django doesn't. In fact, Django's template system is limiting the developer. You can simply use

    {{ if a: }}
        show something 
    {{ else: }}
        show another thing. 
    {{ pass }}
    
  • Both frameworks support layouts.

  • Django has a way better ORM and creating models with Django is easier I think. While Django doesn't automatically import your models, you don't have to use file names such as 0_model.py, 1_model.py. This is not pretty. You can see some examples:

    # Django way:
    from django.db import models
    class Publisher(models.Model):
        name = models.CharField(maxlength=30)
        address = models.CharField(maxlength=50)
        city = models.CharField(maxlength=60)
        state_province = models.CharField(maxlength=30)
        country = models.CharField(maxlength=50)
        website = models.URLField()
    
    # web2py way:
    db.define_table('publisher',
        Field('name', length=30),
        Field('address', length=50),
        Field('city', length=60),
        Field('state_province', length=30),
        Field('country', length=50),
        Field('website', requires=IS_URL())
    )
    
    # Django way:
    p = Publisher(name='Apress',
                address='2855 Telegraph Ave.',
                city='Berkeley',
                state_province='CA',
                country='U.S.A.',
                website='http://www.apress.com/')
    p.save()
    
    # web2py way:
    p = db.publisher.insert(name='Apress',
            address='2855 Telegraph Ave.',
            city='Berkeley',
            state_province='CA',
            country='U.S.A.',
            website='http://www.apress.com/'
    )
    
  • Django has a better URL routing than web2py. I find web2py routes more complex and difficult to set. Also both frameworks supports reverse url routing which is good. Django is a bit better on this since if you add a "name" attribute to the url, you can use it with the "url" template tag.

  • Both frameworks support internationalization however I find web2py's way a lot easier and elegant.

  • Web2py forms are more easy to use than Django forms.

    form1 = SQLFORM(db.publisher) # generates a create form.
    form2 = SQLFORM(db.publisher, db.post[1], deletable=True), # generates an update form.
    
  • Both frameworks support validation but Web2Py doesn't have object validation whereas Django has. (See comment #6.)

  • Django templates support blocks and it supports it really good. Web2py's approach to template blocks was not the way it should be. As of 1.78.1 Web2Py supports blocks as Django.

  • Both frameworks support multiple databases. This is new in Django 1.2 release.

  • Both frameworks have great community. You can get help either on freenode channels or the google groups of both frameworks.

This is all I can recall for now. I will update the post when necessary so do not hesitate to comment and contribute to comparison.

Update (30/04/2010): Added #18.

Update (11/05/2010): Django supports object validation.

Update (18/05/2010): Updated #10. Updated #13. Updated #18. Added #19.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值