How do I access request in form_valid ?
def redirect_logic_func(request):
#redirect logic
class CView(CreateView):
form_class = CForm
template_name = "c_form.html"
def form_valid(self, form):
form.save()
super(CView, self).form_valid(form)
return redirect_logic_func(self.request)
Is self.request.POST the same as request.POST ?
request
variable in form_valid()
, you just need to use self.request
. This will provide you with the request
variable. .post()
to access the request
variable in form_valid()
. self.request.POST
is the same as request.POST
as they are the same request
object.So, your final code should look like:
def redirect_logic_func(request):
#redirect logic
class CView(CreateView):
form_class = CForm
template_name = "c_form.html"
def form_valid(self, form):
form.save()
super(CView, self).form_valid(form)
return redirect_logic_func(self.request) # use self.request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With