Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- views.py
- ________
- from django.shortcuts import render
- from django.core.mail import send_mail
- from django.shortcuts import redirect
- from .forms import ExchangeForm
- from .models import GENRE_CHOICES
- # Create your views here.
- def send_msg(
- email, name, title, artist, genre, price, comment,
- ):
- subject = f"Обмен {artist}-{title}"
- body = f"""Предложение на обмен диска от {name} ({email})
- Название: {title}
- Исполнитель: {artist}
- Жанр: {genre}
- Стоимость: {price}
- Комментарий: {comment}
- """
- send_mail(
- subject, body, email, ["admin@rockenrolla.net",],
- )
- def thank_you_view(request):
- return render(request, "thankyou.html")
- def index(request):
- if request.method == "POST":
- form = ExchangeForm(request.POST)
- if form.is_valid():
- genre = None
- for code, name in GENRE_CHOICES:
- if code == form.cleaned_data["genre"]:
- genre = name
- break
- send_msg(
- form.cleaned_data["email"],
- form.cleaned_data["name"],
- form.cleaned_data["title"],
- form.cleaned_data["artist"],
- genre,
- form.cleaned_data["price"],
- form.cleaned_data["comment"],
- )
- return redirect('/thank-you/')
- return render(request, "index.html", {"form": form})
- form = ExchangeForm()
- return render(request, "index.html", {"form": form})
- __________
- index.html
- __________
- <!DOCTYPE html>
- <!-- Based on https://getbootstrap.com/docs/4.4/examples/pricing/ -->
- <html lang="ru">
- <head>
- <meta charset="utf-8" />
- <meta
- name="viewport"
- content="width=device-width, initial-scale=1, shrink-to-fit=no"
- />
- <title>Уголок рокнрольщика</title>
- <!-- Bootstrap core CSS -->
- <link
- rel="stylesheet"
- href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
- integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
- crossorigin="anonymous"
- />
- </head>
- <body>
- <div class="container">
- <h1>Предложение обмена</h1>
- <p class="lead">
- Предложите мне свой диск на обмен.
- </p>
- <form method="post">
- {% csrf_token %}
- {{ form.as_p }}
- <input type="submit" value="Отправить">
- </form>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment