Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Добрый день. Есть 2 проблемы:
- # 1 мне в contact форме мне приходят письма на почту Reverse for 'chat.views.SuccessView' not found. 'chat.views.SuccessView' is not a valid view function or pattern name.
- # 2 нужно сделать категорию для формы, т.е. сделать выбор к какой категории отнописьмо (категорию выбирает пользователь)
- views
- from django.core.mail import send_mail, BadHeaderError
- from django.http import HttpResponse, HttpResponseRedirect
- from django.shortcuts import render, redirect
- from .forms import FeedBackForm
- def contact(request):
- if request.method == 'GET':
- form = FeedBackForm()
- else:
- form = FeedBackForm(request.POST)
- if form.is_valid():
- subject = form.cleaned_data['name']
- from_email = form.cleaned_data['email']
- message = form.cleaned_data['description']
- try:
- except BadHeaderError:
- return HttpResponse('Invalid header found.')
- return redirect(SuccessView)
- return render(request, "chat/comment.html", {'form': form})
- """ Письмо отправляется, но не приходит
- Content-Type: text/plain; charset="utf-8"
- MIME-Version: 1.0
- Content-Transfer-Encoding: 7bit
- Subject: Name
- From: [email protected]
- Date: @"""
- # Выходит ошибка django.urls.exceptions.NoReverseMatch: Reverse for 'chat.views.SuccessView' not found.
- #'chat.views.SuccessView' is not a valid view function or pattern name.
- # "POST /home/comment/ HTTP/1.1" 500 89420
- def SuccessView(request):
- return HttpResponseRedirect(contact)
- #forms
- from django import forms
- """
- CATEGORY = {
- ('1', '1'),
- ('2', '2'),
- ('3', '3'),
- ('4', '4')
- }
- """
- class FeedBackForm(forms.Form):
- name = forms.CharField(label="Имя пользователя", max_length=150, required=True)
- email = forms.EmailField(label="email", required=True)
- description = forms.CharField(label="Текст", widget=forms.Textarea, required=True)
- # category = forms.ChoiceField(label="Категория", choices=CATEGORY, required=True)
- # HTML
- <div id="contact-form">
- <form action="{% url 'chat:comment' %}" method="POST">
- {% csrf_token %}
- <input type="hidden">
- <li><label for="id_name">Имя</label><input type="text" name="name" maxlength="120" required id="id_name"></li>
- <li><label for="id_email">Email</label><input type="email" name="email" maxlength="120" id="id_email"></li>
- <li>
- <label for="id_category">Как я могу помочь вам?</label>
- <!--<select name="category" id="id_category">
- <option value="">Выберите!</option>
- <option value="1" class="btn-info">Нужна помощь в финансовой грамотносте</option>
- <option value="2" class="btn-info">Давай выпьем кофе</option>
- <option value="3" class="btn-info">У меня есть личный вопрос</option>
- <option value="4" class="btn-info">Есть ошибка на сайте</option>
- </select>-->
- </li>
- <li>
- <label for="id_description">Сообщение</label><textarea type="text" name="description" maxlength="1500" id="id_description" cols="40" rows="10"></textarea>
- </li>
- <button type="submit" class="btn btn-primary">Отправить</button>
- </form>
- </div>
- # URls
- from django.urls import path, include
- from . import views
- app_name = 'chat'
- urlpatterns = [
- path("home/comment/", views.contact, name='comment'),
- path("home/success/", views.SuccessView, name="SuccessView"),
- ]
- # Спасибо
Advertisement
Add Comment
Please, Sign In to add comment