Home Redirect with arguments and message
Reply: 1

Redirect with arguments and message

user3541631
1#
user3541631 Published in 2017-12-07 19:37:48Z

I want to do a redirect with arguments and at the same time send a message to the redirected page.

Where to redirect:

path('companies/<int:pk>/', AccountCompanyDetailView.as_view(), name='detail_company')


from django.shortcuts import redirect

def post_view(request, id):
    return redirect('detail_company', pk=id)

I want to send to the page to wich will be redirected a 'message' to show to the user why it was redirected.

It is possible ?

Santiago M. Quintero
2#
Santiago M. Quintero Reply to 2017-12-07 19:53:59Z

A very simple solution is to modify your urls.py in this way:

  url(r'^'desired_url_to_redirect/(?:(?P<error_key>[0-9]+)/)?$', views.'name_of_your_view', name='name_of_your_view'),

The second parameter is optional and would act as a key for the type error. The only thing left would be to update your template to present the desired message based on the type of error.

For defining your view don't forget to insert as a second parameter 'error_key=None'

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338085 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO