question on django-piston example url mapping

99 views
Skip to first unread message

harm

unread,
Feb 16, 2010, 7:16:30 PM2/16/10
to django-piston
Hi,

When reading the examples in the source code [1] I don't understand
fully how this is supposed to work.

It has the following code
url(r'^posts/$', blogposts),
url(r'^posts/(?P<emitter_format>.+)/$', blogposts),
url(r'^posts\.(?P<emitter_format>.+)', blogposts,
name='blogposts'),

Now how can indidual posts be read ? I don't see an url mapping for
posts/<ik>/
Am I missing something ?
How can individual posts with a certain title be Read (GET)? The
mathing handler.py::read() seems to indicate thats very well possible.

2nd question:
What exactly doe the 3rd line above do ? What does it add ?(compared
to the 2nd).

Regards,
Harm

[1] http://bitbucket.org/jespern/django-piston/src/tip/examples/blogserver/api/urls.py

Regards,
Harm

jespern

unread,
Feb 17, 2010, 2:50:56 AM2/17/10
to django-piston
Hi,

It seems that the url mapping for reading individual posts isn't
there. Must've forgotten. Should be easy to add though.

The difference between the 3 urls:

1. You GET /api/posts/, which will give you all posts, in the default
emitter, JSON.
2. You GET /api/posts/<format>/, which will select another emitter
(e.g. /api/posts/xml/)
3. You GET /api/posts.<format>, again, emitter selection (e.g. /api/
posts.yaml). That way it looks like a "file."


Jesper

> [1]http://bitbucket.org/jespern/django-piston/src/tip/examples/blogserve...
>
> Regards,
> Harm

harm

unread,
Feb 17, 2010, 3:22:52 AM2/17/10
to django-piston
Hi,

I dont get how the *args & **kwargs get filled in:
def read(self, request, *args, **kwargs):

Say I want to select an individual post, by selecting on a field.
api/posts/?title=sometitle
How would that be achieved ?

When I override read()
def read(self, request, *args, **kwargs):
print args
print kwargs

I don't see anything in the args & kwargs, when passing parameters.

Regards,
Harm


Regards,
Harm

jespern

unread,
Feb 17, 2010, 3:24:30 AM2/17/10
to django-piston
Hi,

No, the *args and **kwargs are catch-all here, and aren't really
necessary. If you want the title, you either need to include it in
your url mapping (e.g. (?P<title>.*)), or get it from request.GET.


Jesper

Reply all
Reply to author
Forward
0 new messages