在不使用 url 的情况下将值从 FormView form_valid() 发送到 success_url
Sending value from FormView form_valid() to success_url without using url
如何将这个值发送到success_url?
class AnyView(FormView):
...
success_url = reverse_lazy('success')
def form_valid(self, form):
...
value = 'blablabla' # <<< How to pass this value?
messages.success(self.request, f'Sua matrícula foi realizada.')
return super(AnyView, self).form_valid(form)
success.html
{{ value }}
我不想通过url
发送
path('anyform', AnyView.as_view(), name='anyform'),
@alv2017 的评论对我有帮助。
class AnyView(FormView):
...
def get_context_data(self, **kwargs):
context = super(AnyView, self).get_context_data()
return context
def form_valid(self, form):
...
context['value'] = 'blablabla'
messages.success(self.request, f'Sua matrícula foi realizada.')
return render(self.request, 'success.html', context)
如何将这个值发送到success_url?
class AnyView(FormView):
...
success_url = reverse_lazy('success')
def form_valid(self, form):
...
value = 'blablabla' # <<< How to pass this value?
messages.success(self.request, f'Sua matrícula foi realizada.')
return super(AnyView, self).form_valid(form)
success.html
{{ value }}
我不想通过url
发送path('anyform', AnyView.as_view(), name='anyform'),
@alv2017 的评论对我有帮助。
class AnyView(FormView):
...
def get_context_data(self, **kwargs):
context = super(AnyView, self).get_context_data()
return context
def form_valid(self, form):
...
context['value'] = 'blablabla'
messages.success(self.request, f'Sua matrícula foi realizada.')
return render(self.request, 'success.html', context)