class - Django: how to use bare classes in urls.py urlpatterns? -
I have seen that a URLSASS works like this:
from the project F import some class urlpatterns = pattern ('', (r '^ url / $', some class ()),)
Nowhere can I know what it means , Is usually an entry like this:
(r '^ url / (? P & lt; some_id & gt; \ d +) / $', 'project.views.some_view '),
Can anyone tell me how just some classes () work?
Some class () construction works if this parameter is low, but I have to put the parameter there, so I made something like this:
(r '^ Url / (? P & lt; some_id & gt; \ d +) / $ ', some class ()),
and modify some class which was:
class some class (other class): def item (auto): return MyItems.objects.all ()
to:
class Some classes (other classes): def items (themselves, some_id): return MyItems.objects.filter (pk = some_id)
Now when / url / I go to:
typeError at / url / 12 / items () takes exactly 2 arguments (1 given)
It seems that logic is not passed. If I tried to enter urls.py:
(r '^ url / (? Pi; some_id & gt; \ d +) / $', some classes (some_id)) ,
I get:
error on the name / url / 12 / name 'some_id' is not defined
How to set up the right urlpatterns in this?
Regarding all urlconfs, the value to see that the value is worthy is the example of the callable class As long as the class defines a __ call __
method. This method of accepting the parameters from the URL is required - you did not tell what your 'item' method is, but it is possibly being called from __ call __
.
Comments
Post a Comment