class ModelCreateView(CreateView):
model = Message
fields=['message']
template_name = "page.html"
succes_url = reverse='page'
No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model. this is error but if i put get absolute url reverse going detail page
CodePudding user response:
You need to be change success_url
like this...
class MyModelCreate(CreateView):
model = MyModel
success_url = reverse('index')
---------- OR ------------
success_url = '/index/'
CodePudding user response:
Use get_success_url
as described here in Django documentation:
from django.urls import reverse
class ModelCreateView(CreateView):
model = Message
fields=['message']
template_name = "page.html"
def get_success_url(self):
"""Return the URL to redirect to after processing a valid form."""
return reverse('page')
You can also check this page if you have similar questions regarding this class based view.