4 回答

TA貢獻1796條經驗 獲得超10個贊
求教一個django的view函數參數傳遞問題
流線型化(streamlinling)函數導入1:直接導入視圖函數 from django.conf.urls.defaults import * from mysite.views import hello urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', time), )2:導入包函模塊名和函數的客串,而不是函數本身 from django.conf.urls.defaults import * from mysite import views urlpatterns = patterns('', (r'^hello/$', 'views.hello'), (r'^time/$', 'views.time'),

TA貢獻1770條經驗 獲得超3個贊
Python和Django都推薦極簡主義,能用簡單的方式就不要用復雜的方式。所以,能用函數解決問題,就不要用類。
那為什么Django有類視圖的概念呢?因為Django考慮有一部分視圖的代碼比較重復和通用,就把它提煉出來,放到類里,達到重用的目的。
因此,用不用類,完全取決于你的代碼重復程度。

TA貢獻1873條經驗 獲得超9個贊
流線型化(streamlinling)函數導入1:直接導入視圖函數 from django.conf.urls.defaults import * from mysite.views import hello urlpatterns = patterns('', (r'^hello/$', hello), (r'^time/$', time), )2:導入包函模塊名和函數的客串,而不是函數本身 from django.conf.urls.defaults import * from mysite import views urlpatterns = patterns('', (r'^hello/$', 'views.hello'), (r'^time/$', 'views.time'),
添加回答
舉報