Redirect to page with query string

458 views
Skip to first unread message

Barry Morrison

unread,
Aug 18, 2012, 8:26:32 PM8/18/12
to django...@googlegroups.com
I have a view that displays images and gives me the ability to delete the images. 

View url == /account/community/images/1 (1 == event_id)

That url will display all images associated with event_id=1

Each image displays a 'delete' url  that calls /account/press/page/delete/{{ image.pk }}  -- the success_url for this view is /account/press/page

I'd like the success_url to be /account/community/images{{ event.id }} the page I came from

Code and lengthier explanation exists here: http://dpaste.org/7SGf8/

Thanks!!

Melvyn Sopacua

unread,
Aug 18, 2012, 8:46:28 PM8/18/12
to django...@googlegroups.com
On 19-8-2012 2:26, Barry Morrison wrote:
> I have a view that displays images and gives me the ability to delete the
> images.
>
> View url == /account/community/images/1 (1 == event_id)

Change <a href="images/{{event.pk}}"> to:
<a
href="images/{{event.pk}}?return_to=/account/community/images/{{event.pk}}">.
Keep passing this return_to parameter around. It helps to use the
request context processor so you can just grab it from the request
context in a template.

> I'd like the success_url to be /account/community/images{{ event.id }} the
> page I came from

Subclass the Deleteview and implement get_success_url(), using
request.GET['return_to'] or if you decide to put a hidden input in the
delete form with the return_to value then obviously it's in request.POST.
--
Melvyn Sopacua

Barry Morrison

unread,
Aug 18, 2012, 9:29:36 PM8/18/12
to django...@googlegroups.com
I apologize, I'm new to Django and Python...I've tried every which way I know how based on what you described, and I can't find success. 

Here is what I'm at right now:

http://dpaste.org/7JcGT/

I get this error: 'DeleteCommunityImages' object has no attribute 'GET'

Full traceback: http://dpaste.org/QZ6uB/

Thanks,
Barry


--
Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


Barry Morrison

unread,
Aug 19, 2012, 3:25:13 AM8/19/12
to django...@googlegroups.com
This actually ended up working: http://dpaste.org/U0uY4/ 

Melvyn Sopacua

unread,
Aug 19, 2012, 6:04:21 AM8/19/12
to django...@googlegroups.com
On 19-8-2012 3:29, Barry Morrison wrote:
> I apologize, I'm new to Django and Python...I've tried every which way I
> know how based on what you described, and I can't find success.
>
> Here is what I'm at right now:
>
> http://dpaste.org/7JcGT/
>
> I get this error: 'DeleteCommunityImages' object has no attribute 'GET'

Because the first parameter on an object method is the object:
def get_success_url(self) :
return self.request.GET['return_to']

On class-based views several things are assigned to the object as
attributes and the request object is one of them:
<https://docs.djangoproject.com/en/1.4/topics/class-based-views/#dynamic-filtering>

It probably should be documented better what is available on the view
object and 1.5 docs are improving a lot:
<https://docs.djangoproject.com/en/dev//ref/class-based-views/#specification>

(allthough it still doesn't mention request specifically)

<https://docs.djangoproject.com/en/dev//ref/class-based-views/generic-editing/#deleteview>
Here you see it uses the DeletionMixin:

<https://docs.djangoproject.com/en/dev//ref/class-based-views/mixins-editing/#django.views.generic.edit.DeletionMixin>
and the method signature for get_success_url()

--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages