DJANGO VS. WEB2PY
Posted 工程师WWW
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
--------------------- 本文来自 snail200x 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/snail200x/article/details/9612283?utm_source=copy
以上是关于DJANGO VS. WEB2PY的主要内容,如果未能解决你的问题,请参考以下文章
web2py--------------用web2py写 django的例子 --------开发环境
Django、Turbo Gears、Web2Py,哪个更好?
web2py--------------用web2py写 django的例子 --------建立一个投票应用