Django error: name 'csrf' is not defined
Here's my views.py:
class EContactsView(View):
template_name = 'base/contacts.html'
# В случае get запроса, мы будем отправлять просто страницу с контактной формой
def get(self, request, *args, **kwargs):
context = {}
context.update(csrf(request)) # Обязательно добавьте в шаблон защитный токен
context['contact_form'] = ContactForm()
return render(template_name=self.template_name, context=context)
def post(self, request, *args, **kwargs):
context = {}
form = ContactForm(request.POST)
# Если не выполнить проверку на правильность ввода данных,
# то не сможем забрать эти данные из формы... хотя что здесь проверять?
if form.is_valid():
email_subject = 'EVILEG :: Сообщение через контактную форму '
email_body = "С сайта отправлено новое сообщение\n\n" \
"Имя отправителя: %s \n" \
"E-mail отправителя: %s \n\n" \
"Сообщение: \n" \
"%s " % \
(form.cleaned_data['name'], form.cleaned_data['email'], form.cleaned_data['message'])
# и отправляем сообщение
send_mail(email_subject, email_body, settings.EMAIL_HOST_USER, ['target_email@example.com'], fail_silently=False)
return render(template_name=self.template_name
How to fix it the error with csrf? The problem is not discovered in terminal.