0

I have 2 pages which allow to send user a private message.

On both of these pages I have a form which is processed by the same view e.g.

def send_message(request, pk)
    # send this user a message
    return redirect_to_page_which_sent_POST_request

So my goal is to use the same method to precess forms on both pages, and redirect back to the page.

I know I can do this by adding next parameter to the form but are there any simpler ways?

GRS
  • 2,807
  • 4
  • 34
  • 72

1 Answers1

0

I had a similar problem once and I solved it via the URL. Say you have two pages foo and bar, I added the following to the url.

/(?P<source>(foo|bar))/

Then on on page foo / bar add source='foo' / 'bar' to the POST url. You can then use

if source == 'foo':
    return redirect(reverse('foo'))
else:
    return redirect(reverse('bar'))

in your view.

DisneylandSC
  • 926
  • 1
  • 5
  • 19