[See the blog entry](http://sciyoshi.com/blog/2008/nov/18/rails-mvc-controllers-django/)
Allows using controllers for views.
This allows for nice subclassing to override behavior of views. `Controller.urls` (see below) works fine for subclasses as well.
Similar to [snippet #1165](http://www.djangosnippets.org/snippets/1165/) except that it won't break reverse URL resolving and regex validation in URLs.
In `views.py`:
import mvc
class MyController(mvc.Controller):
@mvc.view('myview/$', 'myview')
def my_view(self):
# do something with self.request
return HttpResponse('something')
class Meta(mvc.Controller.Meta):
url_prefix = 'mycontroller-'
In `urls.py`:
from . import views
urlpatterns = patterns('',
# ... other urls here ...
*views.MyController.urls(r'prefix/')
)
Then the view `MyController.my_view` will be accessible from `'prefix/myview/'` and have the name `'mycontroller-myview'`, i.e. `reverse('mycontroller-myview')` will work as expected.