Right on - a better solution if you're keeping it all in the same server!

-joe

On 10/1/07, Marty Alchin <[EMAIL PROTECTED]> wrote:
>
> On 10/1/07, Joseph Heck <[EMAIL PROTECTED]> wrote:
> > You could do it by having your view act as a proxy. Basically
> > instantiate a new connection to the view in question from your web
> > application using urllib2 or the like. Then get the results, process
> > them as you wish, and send the results of that post-processing (if
> > any) back to the original client request.
>
> To be fair, that's even more overhead than is really necessary. You
> can actually just do "from django.http import HttpRequest" and create
> a request that way, and just pass it to the other view. There's no
> need to actually involve any HTTP traffic, plus it wouldn't rely on
> any particular URL scheme. It would go straight to the view, no
> questions asked.
>
> Something like the following could work, but what you add to the the
> request object will depend on what the other view does with it.
>
> from django.http import HttpRequest
>
> from myapp.views import real_view
>
> def proxy_view(request):
>     req = HttpRequest()
>     req.method = 'POST'
>     req.POST = {'arg1': 'value1', 'arg2': 'value2'}
>     response = real_view(req)
>     if response.status == 200:
>         return response
>     else:
>         # Handle errors here
>
> Keep in mind that in this scenario, real_view won't have any
> middleware processing, it'll just get the request exactly as you pass
> it. So if the view needs request.user, for instance, you'll have to
> set it manually (req.user = request.user) before passing the new
> request to the view.
>
> Of course, if all you're doing is adding POST data, you could probably
> get by with just changing the method on the actual request, and adding
> POST data, then triggering the other view:
>
> from myapp.views import real_view
>
> def proxy_view(request):
>     request.method = 'POST'
>     request.POST = {'arg1': 'value1', 'arg2': 'value2'}
>     return real_view(request)
>
> I hope this helps.
>
> -Gul
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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