How can I use a method as a view? (so that I can subclass and extend later.)

foo works, the other 2 give errors:

#  msg/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('msg.views',
     (r'^detail/(?P<object_id>[-\w]+)/$', 'foo'),
     (r'^detail/x/(?P<object_id>[-\w]+)/$', 'MsgViews.message_detail'),
     (r'^detail/y/(?P<object_id>[-\w]+)/$', MsgViews.message_detail),
)


# msg/views.py
from django.shortcuts import render_to_response, get_object_or_404
from core.models import Message

class MsgViews(object):

     def message_detail(self, request, object_id=None):
         m=get_object_or_404(Message, pk=object_id)
         return render_to_response('message_detail.html', {'message': m})

def foo(request, object_id=None):
     mv=msgviews()
     return mv.message_detail(request, object_id)

'MsgViews.message_detail':   Could not import msg.views.MsgViews. Error was: No 
module named MsgViews

MsgViews.message_detail:  unbound method message_detail() must be called with 
MsgViews instance as first argument (got WSGIRequest instance instead)

I was given this in #django
mattmcc: You can make a class into a callable object to use in urlconfs.
Which sounds familiar, but I don't know how to do.

Carl K

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to