문제

I am using a form wizard and want to implement a cancel-button that brings me back to the page on which I clicked the link that brought me to the formwizard. Is there a smart way to do this? At the moment I am adding a redirect to the link that starts the form wizard like that:

<td><a href="/lecture/add/?redirect={{ request.path }}">create new lecture</a></td>

Then in get_context_data I add self.request.GET.get('redirect') to the context. In my template I then have a Cancel-Button that redirects to the link from the context. But this works only in Step 1. In all other steps the information is gone. So does anyone have an idea how to solve this? Help is much appreciated!

도움이 되었습니까?

해결책

You might want to use a hidden input field to transmit the cancel action each time the form is submitted:

<input type="hidden" name="redirect" value="{{ cancel_action }}" />

And then read it in the view:

def get_context_data(self, form, **kwargs):
    # ...
    if self.request.GET.get('redirect'):
        # ...
    elif self.request.POST.get('redirect'):
        context.update({ 'cancel_action' : self.request.POST.get('redirect') })
    # ...
    return context
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top