Re: Redirect question

21 views
Skip to first unread message

Daniel Roseman

unread,
Jun 29, 2012, 11:01:41 AM6/29/12
to django...@googlegroups.com
On Friday, 29 June 2012 15:45:16 UTC+1, ivanb wrote:
I'm still learning django so please forgive if I write anything silly.

On my site I'm having something like: on url mysite/list/ I have list of something. On it I have link that leads to another view if you want to add new element to it let's say: mysite/list/add_item/ 

On that url I have form with some information that needs to be written and a file upload in the form. On form submit it actually goes to new view mysite/list/adding/ and there the needed work is done.

After the work is done I want to go back to the first url and view  mentioned. Thing is I would also like it to show a message up there about status of what happened, so I can't use redirect, and if I put render_to_response it actually shows the proper view with the appropriate message but url is not the right one, it keeps the mysite/list/adding/ (that is logical behaviour and I understand it) but I want mysite/list/.

I'm asking for a way to achieve this, do some work and redirect to some previous view with some context added. Also I would like you to point out if I did something here that could have been done in better way so I can do it right and learn for the future.

Also, I know it could be done with setting some get parameters for the redirect but I would like to keep the url clean if possible.

If you know please advise.

Thanks

Use the messages framework to add a message to the user when you process, and display it on the page you redirect to.
--
DR. 

Kurtis Mullins

unread,
Jun 29, 2012, 11:43:31 AM6/29/12
to django...@googlegroups.com
[...] 
Also I would like you to point out if I did something here that could have been done in better way so I can do it right and learn for the future.

If you're using Class Based Views, you can use a mixin to achieve this. Here's mine if you want to check it out: http://stackoverflow.com/questions/5531258/example-of-django-class-based-deleteview/10903943#10903943 (Scroll Down to the Bottom)

This may be a bit advanced for you at the moment but it works really well for me. You can ignore most all of the other code in that posting and just focus on the MessageMixin. Also, see the documentation link posted by Daniel Roseman. The messaging framework is the way to go for passing on a "Success" or some type of a notification message.
Reply all
Reply to author
Forward
0 new messages