django redirect to view

I have one view that I want to do some stuff in and then redirect to another view with a success message. The signature of the method that I want to redirect to is

quizView(request, quizNumber, errorMessage=None, successMessage=None): 

and my attempt at redirecting to that view looks like this:

return redirect(quizView, quizNumber=quizNumber, errorMessage=None, successMessage="Success!")

I've tried most every combination of named and un-named paramaters and I can't get it to do what I want. Is there a way to make this work?

Also, I tried just returning the the second view with the first but then the URL is still where it was in the old view instead of appearing as though it has redirected.

Thanks!

Answers


You haven't given your URL a name, so you need to use the whole path to the view function. Plus, that URL doesn't take errorMessage or successMessage parameters, so putting them into the reverse call will fail. This is what you want:

return redirect('quizzes.views.quizView', quizNumber=quizNumber)

Can you try example 2 given in https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect

  • Make sure that it does the 'reverse' on the given view.
  • Your view name should be wrapped in single quotes/

You should Refer this https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#redirect

For redirect inside view. Its very easy either you redirect using creating a url for view or call inside the view also.


Need Your Help

Efficiency of operations on R data structures

r performance

I'm wondering if there's any documentation about the efficiency of operations in R, specifically those related to data manipulation.

Round with integer division

python rounding integer-division

Is there is a simple, pythonic way of rounding to the nearest whole number without using floating point? I'd like to do the following but with integer arithmetic: