I've seen somewhere a urls.py construct like this:
from project.f import SomeClass
urlpatterns = patterns('',
(r'^url/$', SomeClass()),
)
Nowhere in http://docs.djangoproject.com/en/dev/topics/http/urls/ I can find out what this means, normally an entry is like this:
(r'^url/(?P<some_id>\d+)/$', 'project.views.some_view'),
Can someone explain me how putting just SomeClass() in there works?
The SomeClass() construct works if it is parameter-less, but I wanted to have parameters in there, so I made something like this:
(r'^url/(?P<some_id>\d+)/$', SomeClass()),
and modified SomeClass which was:
class SomeClass(OtherClass):
def items(self):
return MyItems.objects.all()
to:
class SomeClass(OtherClass):
def items(self, some_id):
return MyItems.objects.filter(pk=some_id)
Now when visiting /url/ I get:
TypeError at /url/12/
items() takes exactly 2 arguments (1 given)
so it looks like the arguments are not passed. If I tried putting in urls.py:
(r'^url/(?P<some_id>\d+)/$', SomeClass(some_id)),
I get:
NameError at /url/12/
name 'some_id' is not defined
How to make correct urlpatterns in this setup?