
from django.http import HttpResponseRedirect
from django.shortcuts import render
from subscribers.forms import SubscriberForm
from .models import Subscriber
from django.views.generic import TemplateView

class successfulSubscriptionView(TemplateView):
    """Display the about page"""
    template_name = 'subscribers/SuccessfulSubscription.html'

def subscribe(request):
    # 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 = SubscriberForm(request.POST or None)
        # check whether it's valid:
        if form.is_valid():
            model = Subscriber()
            model.email = form.cleaned_data['SubscriberEmail']
            model.save()            # process the data in form.cleaned_data as required
            # redirect to a new URL:
            #return render(request, './subscribers/SubscribeForm.html', {'form': form})
            return HttpResponseRedirect('SuccessfulSubscription') # todo Make a thanks page
    # if a GET (or any other method) we'll create a blank form
    else:
        form = SubscriberForm()
    return render(request, 'subscribers/SubscribeForm.html', {'form': form})

from django.http import HttpResponseRedirect
from django.shortcuts import render
from subscribers.forms import SubscriberForm
from .models import Subscriber
from django.views.generic import TemplateView

class successfulSubscriptionView(TemplateView):
    """Display the about page"""
    template_name = 'subscribers/SuccessfulSubscription.html'

def subscribe(request):
    # 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 = SubscriberForm(request.POST or None)
        # check whether it's valid:
        if form.is_valid():
            model = Subscriber()
            model.email = form.cleaned_data['SubscriberEmail']
            model.save()            # process the data in form.cleaned_data as required
            # redirect to a new URL:
            #return render(request, './subscribers/SubscribeForm.html', {'form': form})
            return HttpResponseRedirect('SuccessfulSubscription') # todo Make a thanks page
    # if a GET (or any other method) we'll create a blank form
    else:
        form = SubscriberForm()
    return render(request, 'subscribers/SubscribeForm.html', {'form': form})
Display the about page # if this is a POST request we need to process the form data # create a form instance and populate it with data from the request: # check whether it's valid: # process the data in form.cleaned_data as required # redirect to a new URL: #return render(request, './subscribers/SubscribeForm.html', {'form': form}) # todo Make a thanks page # if a GET (or any other method) we'll create a blank form