I think I found the solution even though it differs from what I
initially was looking for, i.e. being able to use Django HttpResponse
for returning responses inside Restish Resource's instead of webob,
but that's not a problem really (webob is probably better than Django
HttpResponse anyway :P).
Anyway, I found this:
http://code.djangoproject.com/ticket/8927#comment:8
which is basically about making it possible to call other WSGI apps
inside Django,
And the code I ended up using is:
http://github.com/rfk/django/blob/f96eb6068552e228f705beda9c8181db2079a797/django/wsgi/wsgi_to_django.py
Which just takes a WSGI app objet and wraps it as a regular Django
view that you can put into your Django URLconf. There are hacks
involved, but it works (and afaik also handles file uploads).
The code I have now is trivial:
from wsgi_to_django import django_view_from_wsgi_app
from
restish.app import RestishApp
from restish import http, resource
class Root(resource.Resource):
@resource.child(resource.any)
def html(self, request, segments):
return http.ok([('Content-Type', 'text/html')],
"<p>Hello from resttest!</p>")
restish = django_view_from_wsgi_app(RestishApp(Root()))
I still have one question though: Restish doesn't automatically add a
trailing slash to URLs, so a @resource.GET method on a Resource does
not catch /foo/bar/ but just /foo/bar instead, which means I have to
declare a @resource.child('') or @resource.child(resource.any) in
order to catch /foo/bar/. Is there a way to change this behaviour in
Restish, i.e. to have Restish at least treat /bar/ equal to /bar, or
even better, redirect /bar to /bar/? (Although the latter is not
important for me as Django already does this for me.)
Thanks to everyone for their time,
Erik Allik
On 26 Aug, 21:41, Erik Allik <
eal...@gmail.com> wrote:
> Yoan and Matt, thanks for your responses!
>
> I can't migrate away from Django at the moment because of its ORM,
> auth, templating and parts that have been written in a Django specific
> way. The reason I'm looking at Restish is because our front end URL
> mapping is something that Restish would fit for perfectly because all
> URLs in our application map to objects in the database, not views, and
> the hierarchy of objects is generic, i.e. something that Django can't
> handle (which is why I've set up a (.*) catch-all view in Django that
> does the actual URL parsing and dispatching - this is the part that
> Restish would handle elegantly).
>
> I assume it's possible to access the WSGI environment from a Django
> view and just delegate to Restish using that. I just posted here to
> get feedback on how this could be done elegantly (I'm not saying using
> Restish inside a Django app is elegant, but I can't change that right
> now).
>
> Maybe I should phrase it this way: is it possible to decouple Restish
> from WebOb and other parts that would block me from using it with
> Django? Can I just use the part of Restish that treats all URLs as
> resources while still returning Django HttpResponse objects from those
> Restish resource handlers?
>
> Erik
>
> On 26.08.2009, at 21:13, Matt Goodall wrote:
>
>
>
>
>
> > 2009/8/26 Yoan Blanc <
yoan.bl...@gmail.com>: