path('', include('core.urls')),
path('blog/', include('blog.urls')),
path('contact/', views.ContactView.as_view(), name='contact'),
{% include 'contact/contact.html' %}
class ContactView(FormView):
form_class = ContactForm
template_name = 'contact.html'
success_url = '#' # адрес страницы успеха отправки формы
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('files')
if form.is_valid():
form.save()
id = form.save().pk
contact = Contact.objects.get(pk=id)
for f in files:
# pdb.set_trace()
fl = Files(contact=contact, file = f)
fl.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('files')
if form.is_valid():
form.save()
for f in files:
Files.contact = form
Files.file = f
Files.save
return self.form_valid(form)
else:
return self.form_invalid(form)
class Files(models.Model):
file = models.FileField(upload_to='contact', blank=True, null=True, verbose_name='Файл')
contact = models.ForeignKey(Contact, blank=True, null=True, on_delete=models.CASCADE)
def product_view(request, prod_id=None):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = FeedbackForm(request.POST)
# check whether it's valid:
if form.is_valid():
template_name = 'app_main/mail.html'
name = form.cleaned_data['name']
....
А использовать {{ form.as_p }} в любом месте, как понимаю, уже не получится?