Django success url
Прописываю в success_url путь success_url = 'main/index.html'
Однако выдает ошибку, что путь не найден:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/main/index.html
Using the URLconf defined in caparol_center_spb_decision.urls, Django tried these URL patterns, in this order:
admin/
[name='index']
decision/
The current path, main/index.html, didn't match any of these.
Хотя он есть в папке templates/main/index.html
views:
class ContactView(FormView):
template_name = 'main/index.html'
form_class = EmailForm
success_url = 'main/index.html'
success_message = "Письмо успешно отправлено"
def form_valid(self, form):
email = form.cleaned_data['email']
send_mail('Caparol_Center_Spb',
'Теперь вы будете получать лучшие предложения шоу-рума',
email,
[email, ],
fail_silently=False,)
return super().form_valid(form)
def form_invalid(self, form):
return HttpResponse('Unsuccess')
urls:
from django.urls import path
from .views import ContactView
app_name = 'main'
urlpatterns = [
path('', ContactView.as_view(), name='index')
]
Ответы (1 шт):
Автор решения: Віктор Дума
→ Ссылка
В success_url нужно вписывать не путь к HTML-файлу, а сам URL-адрес.
Думаю, в вашем случае файл main.html отвечает за URL-адрес "/", то есть вам нужно прописать следующее: success_url = "/".