V
V
Vladislav Voznesensky2020-05-05 18:32:29
Django
Vladislav Voznesensky, 2020-05-05 18:32:29

Is it possible to call as_view from a controller?

Is it possible to call as_view() of a class from a controller?
I need to pass a variable that is initialized in the controller.

This is what routing looks like

urlpatterns = [
    path('form/check/', room_check, name='room_check'),
    path('contact/', BookWizard.as_view(FORMS, initial_dict=initial)),
]


BookWizard - a class inherited from SessionWizardView from the formtools module

Next is the controller piece where the variable is created
initial = {
                    '0': {'check_in_date': check_in_date,
                          'date_of_eviction': date_of_eviction,
                          'category': category,
                          'number_of_adults': number_of_adults,
                          'number_of_children': number_of_children}}

                return redirect(BookWizard.as_view(FORMS, initial_dict=initial))


As a result, I get the following error:
5eb186eb056b5863838872.png

Maybe there is another way to pass a variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
roa, 2020-05-06
@roa

urls.py

...
path('contact/', BookWizard.as_view(FORMS, initial_dict=initial), name='contact'),
...

views.py
from django.urls import reverse
...
url_contact=reverse('contact')
return redirect(reverse)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question