I am trying to create a small subscription input form on top of my page that allows users to enter their email, click "submit" and then it will call the subscribe function on the back-end.
I am putting the form code in one of my template html file:
<div class="container">
<div class="wrapper d-flex align-items-stretch" style="margin-bottom: 100px;">
{% include 'Reddit_app/sub_list.html' %}
<div id="content" class="mr-4">
<div class=" lt-area">
<div class="tr-inner">
<form action="{% url 'subscribe' station.slug %}" method="POST" class="subscribe-form">
<div class="form-group d-flex mb-1">
<div class="icon"><span class="icon-paper-plane"></span></div>
<input type="email" name="email" class="form-control" placeholder="Subscribe us">
</div>
<button type="button" class="btn btn-primary t-btn">Submit</button>
</form>
</div>
</div>
{% block content %}
{% endblock %}
</div>
</div>
</div>
Here is my urls.py
urlpatterns = [
...
path('<slug:slug>/subscribe/', views.subscribe, name='subscribe'),
]
and here is my subscibe function, but right now when I click submit, this function is currently not even called
def subscribe(request, slug):
station=get_object_or_404(Station, slug=slug)
post_data = request.POST.copy()
email = post_data.get("email", None)
try:
validate_email(email)
except ValidationError as e:
print("bad email, details:", e)
return redirect('post_list', slug=station.slug)