-1

In my djangoApp , views.py I have :

status = True
context = {'status': status ,
           "form":ProfileForm()
          }
    return render(request, "sample/Newsample.html", context)

What if I want to use the context with redirect function? for example:

status = True
context = {'status': status ,
           "form":ProfileForm()
          }
    return redirect("sample/Newsample.html", context) - this does not work!!

How can I use context with redirect function?

user3369157
  • 137
  • 1
  • 9
  • What you want to do exactly ? – Nishant Nawarkhede Apr 24 '14 at 05:51
  • I have a variable in my template called status , which would display contents when status var is true. I want to pass this status var to Newsample.html through the redirect() func. – user3369157 Apr 24 '14 at 05:58
  • 1
    You're confusing redirect with render. redirect sends you to a new url. Django will handle this url as it handles any other http request and create any context in the appropriate view. You can pass a url, a url name, or a model(as long as it as get_absoluteurl() defined) to a redirect. docs: https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect You wouldn't usually create a context object in a redirect view. Well, if your view accepts a context variable (which would be less than orthodox), you could send one, but that would just be a bit necessary – skzryzg Apr 24 '14 at 06:03
  • DUPLICATE of http://stackoverflow.com/questions/1463489/how-do-i-pass-template-context-information-when-using-httpresponseredirect-in-dj and http://stackoverflow.com/questions/3624422/how-do-i-redirect-in-django-with-context – xyres Apr 24 '14 at 06:03
  • but if you wanted to you could also send them with some get variables – skzryzg Apr 24 '14 at 06:04
  • The behavior you're describing would probably be better served by a context processor than a redirect: https://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors – skzryzg Apr 24 '14 at 06:06
  • How to send it through get variables? – user3369157 Apr 24 '14 at 06:22

1 Answers1

0

redirect function doesn't any template as argument. It needs view name or url as the first argument.

Check this is required structure for redirect.

redirect(to[, permanent=False], *args, **kwargs)

If you want to send data with redirect, try this:

def my_view(request):
    ...
    return redirect('some-view-name', status=True)
Shanki
  • 167
  • 3