Reputation: 47
class A_modelCreateView(CreateView)
in views.pypath('create/'),view.A_modelCreateView().as_view(),name='create'
in urls.pyIs there filled parameter somewhere for redirect the url you want?
Upvotes: 2
Views: 352
Reputation: 477607
Yes, a CreateView
has as one of its baseclasses a the FormMixin
. This FormMixin
class has a success_url
attribute [Django-doc].
You can add a real url, or work with reverse_lazy
[Django-doc] to calculate the URL based on the name of a view. For example:
from django.urls import reverse_lazy
from django.views.generic.edit import CreateView
class A_modelCreateView(CreateView):
success_url = reverse_lazy('overview_page')
# ...
where overview_page
is here the name of a hypothetical view.
If you do not specify a success_url
in a CreateView
or UpdateView
, it will take the get_absolute_url
of the model object that is created/updated, if the model has such method. For more information, see the Django documentation.
Upvotes: 3