Thanks.  Yes, your point about ajax is a good one, and in some cases
that is what I want, but in other cases I want to reexecute the
views.py code for the current page because now it will display
something new, due to the "action" I just completed.

For example, I am listing the posts for a forum and the forum is
"locked".  So instead of it having "reply" button, it has an "unlock"
button.  When they click on unlock, it will take me to views.py code
that unlocks it, and after it is unlocked, I want to return to the
listing of posts, but this time I want the button to say "reply"
instead of unlock.

I went ahead and used the same mechanism used by the account module,
ie:

        # light security check -- make sure redirect_to isn't
garabage.
        if not redirect_to or "://" in redirect_to or " " in
redirect_to:
            return HttpResponseRedirect(reverse('topic_list', args=
(topic.forum.id,)))
        else:
            return HttpResponseRedirect(redirect_to)

Then in my html on the button that does the unlock I have something
like this:

<a href="{% url topic_unlock topic.id %}?next={% url post_list
topic.id  %}"

I just thought maybe there was django magic that wouldn't require me
to pass in the "next" url.

Thanks for your insights!


On Apr 21, 2:33 pm, google torp <toppe...@gmail.com> wrote:
> On Apr 21, 10:53 pm, Margie <margierogin...@yahoo.com> wrote:
>
> > Can anyone advise me on what is the best way in the views.py code to
> > return an HttpResponse that simply returns the user to the previous
> > page they were on?
>
> > For example, let's say that multiple different pages have a button
> > that executes some code in views.py, but is not intended to actually
> > take the user to a new page.  So after executing that code, I just
> > want to redisplay the previous page they were looking at.
>
> It sounds like you don't want to leave the page while your code is
> running
> and then come back but just stay on the same page. A good option for
> this would be AJAX using javascript. Another way would be to use the
> same template. Users won't know what views function is run so more
> than one can use the same template making it look like they are on the
> same page.
>
> > On a slightly more complicated note, say multiple different pages have
> > a button that executes some code and then does redirect the user to
> > page 'foo'.  Now when the user clicks a 'submit' button on page
> > 'foo',  I would like to take them back to wherever they were before
> > they got to page 'foo'.
>
> It sounds like you want to have a link to a form that when the user
> has
> filled it out and submited you want to take them back to that page. I
> would suggest that you send along to the view a variable containing
> data where to send them back and use to redirect them to the right
> place. I don't know if Django has an easier way to do it, but else
> that
> way is a pretty general way of doing it.
>
> ~Jakob
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to