Ok, I'll try to elaborate. again java is foreign to me although I've
spent all day trying to learn some.
Here's the code:
def please_wait(request):
# ... setup context or something
return render_to_response("please_wait.html")
def run_DHM(request)
# ... perform calculations and collect the result in a dict
data = {"result": something}
return HttpResponse(json.dumps(data), mimetype="application/json")
# using jquery in your html
<script type="text/javascript">
$.getJSON("/run_DHM/", function(data) {
// do something with result
console.log(data.result);
});
</script>
def run_DHM(request) is straight forward then it falls apart.
$.getJSON("/run_DHM/", function(data) {
// do something with result
console.log(data.result);
});
I presume that '$.getJSON("/run_DHM/", function(data)' somehow runs
the run_DHM function? How can it even find the function since it lives
in view.py? '// do something with result'???? I want to send another
page to the client with the results but do I do this here? If not,
what do I do here? What does 'console.log(data.result);' do? Why does
def run_DHM(request) return a HttpResponse? I have a template I want
it to return so shouldn't I use render_to_response? Obviously, I am
not getting how the javascript works so I have no idea how to set this
up. I was hoping there was a pythonic solution :).
I hope this explains my utter confusion sufficiently.
Bradley
On Tue, Aug 31, 2010 at 4:12 PM, Alec Shaner <[email protected]> wrote:
> Rolando's suggestion is a pretty straight forward method to achieve what you
> want. You probably need to elaborate where in the process you're having
> trouble (although based on your response maybe it's the first step?). You
> can indeed call a view.my function from your please wait template, but you
> want to do it in the background, i.e., with an AJAX request in order to keep
> the Please Wait message displayed while your server processes the request.
>
> On Tue, Aug 31, 2010 at 2:46 PM, Bradley Hintze
> <[email protected]> wrote:
>>
>> I'm getting no where with this, are there any other suggestions on row
>> to render a 'please wait' page while other python works? Can I call a
>> view.my function to run from my 'please wait' template?
>>
>> Please be as elementary as possible as javascript, AJAX, jquery, and
>> the like are brand new to me.
>>
>> Thanks,
>> Bradley
>>
>> On Tue, Aug 31, 2010 at 10:38 AM, Bradley Hintze
>> <[email protected]> wrote:
>> > I'll look into this. I have no idea what you mean by 'ajax' or 'json'.
>> > Thus your code doe'snt really make sense given my lack of knowlege. I
>> > will do some googling to see if I can piece it together. Thanks for
>> > the help!
>> >
>> > On Mon, Aug 30, 2010 at 10:37 PM, Rolando Espinoza La Fuente
>> > <[email protected]> wrote:
>> >> On Mon, Aug 30, 2010 at 7:18 PM, Bradley Hintze
>> >> <[email protected]> wrote:
>> >>> I am attempting to do a lengthe calculation that will require the user
>> >>> to wait a bit. I want a 'Please wait page to come up while the lengthy
>> >>> calculation is performed. I thought this might work:
>> >>>
>> >>> views.py
>> >>>
>> >>> def please_wait(request):
>> >>> return HttpResponse('Please Wait......')
>> >>>
>> >>> def run_DHM(request):
>> >>> please_wait(request)
>> >>> ....lengthy calculations...
>> >>>
>> >>> This did not show the 'Please Wait' page. Is there a better way to do
>> >>> what I am trying to do?
>> >>>
>> >>
>> >> You are not returning the HttpResponse object from please_wait(). But
>> >> anyway,
>> >> doesn't work that way. At least with django.
>> >>
>> >> What you can do is render a normal html with the message "Please wait",
>> >> then perform an ajax call to start the calculations and finally return
>> >> a json response
>> >> to display the result in the client-side.
>> >>
>> >> Roughly:
>> >>
>> >> def please_wait(request):
>> >> # ... setup context or something
>> >> return render_to_response("please_wait.html")
>> >>
>> >> def run_DHM(request)
>> >> # ... perform calculations and collect the result in a dict
>> >> data = {"result": something}
>> >> return HttpResponse(json.dumps(data), mimetype="application/json")
>> >>
>> >>
>> >> # using jquery in your html
>> >> <script type="text/javascript">
>> >> $.getJSON("/run_DHM/", function(data) {
>> >> // do something with result
>> >> console.log(data.result);
>> >> });
>> >> </script>
>> >>
>> >>
>> >> Rolando Espinoza La fuente
>> >> www.insophia.com
>> >>
>> >>> --
>> >>> Bradley J. Hintze
>> >>> Graduate Student
>> >>> Duke University
>> >>> School of Medicine
>> >>> 801-712-8799
>> >>>
>> >>> --
>> >>> You received this message because you are subscribed to the Google
>> >>> Groups "Django users" group.
>> >>> To post to this group, send email to [email protected].
>> >>> 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.
>> >>>
>> >>>
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Django users" group.
>> >> To post to this group, send email to [email protected].
>> >> 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.
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Bradley J. Hintze
>> > Graduate Student
>> > Duke University
>> > School of Medicine
>> > 801-712-8799
>> >
>>
>>
>>
>> --
>> Bradley J. Hintze
>> Graduate Student
>> Duke University
>> School of Medicine
>> 801-712-8799
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to [email protected].
>> 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.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> 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.
>
--
Bradley J. Hintze
Graduate Student
Duke University
School of Medicine
801-712-8799
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.