All good
I use CreateView to generate models:
class Create(CreateView): form_class = user.CreatePerson template_name = 'welcome.html' succes_url = '/success/' # reverse_lazy('contact') или reverse def form_valid(self, form): Profile.objects.create(**form.cleaned_data) suc = self.get_success_url() #contact_name = self.form.cleaned_data['contact_name'] return redirect(suc) In the template it is:
<body> <form method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Save"> </form> </body> I do not specify the action form, since I assume that in case of successful validation, the site redirects me to the link given in the succes_url of my class inherited from CreateView. But after successful validation django swears the following text on the line suc = self.get_success_url() :
No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model. Googling a bit, I found the tips in the spirit and made the simplest method in the model that I could think of:
def get_absolute_url (self): return '/ success /'
In url-ah with me
url(r'^success/$', TemplateView.as_view(template_name="gradulations.htm")), But the error remained. What can I do to get away from her?