Skip to content

Instantly share code, notes, and snippets.

@bld2104
Last active March 27, 2018 17:02
Show Gist options
  • Save bld2104/68b92c646fef54113f7793d68880b453 to your computer and use it in GitHub Desktop.
Save bld2104/68b92c646fef54113f7793d68880b453 to your computer and use it in GitHub Desktop.
###############
## This is just for trying to get the newsletter sign-up form on a new page, not the other issue I mentioned
## This is literally all I added
###############
# views.py
from newsletter.models import Newsletter
class EmbedNewsletterSubscribeView(TemplateView):
template_name = 'testnewslettersubscribe.html'
def get_context_data(self, **kwargs):
context = super(EmbedNewsletterSubscribeView, self).get_context_data(**kwargs)
newsletter = Newsletter.objects.get(slug="bla")
context['newsletter_form'] = NewsletterForm(newsletter=newsletter)
return context
# urls.py
path('testnewsletter', views.EmbedNewsletterSubscribeView.as_view(), name='testnewsletter'),
# testnewslettersubscribe.html
{% extends 'base.html' %}
{% load static %}
{% block title %}Thank you{% endblock %}
{% block content %}
<div class="container">
<h1>Thank you!</h1>
<h2>Your data was successfully submitted.</h2>
<div class="row" style="background-color:red; height:300px"></div>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"></div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
<form enctype="multipart/form-data" method="post" action="/newsletter/<newsletter-name>/subscribe">
{% csrf_token %}
{{ form.as_p }}
<p><input id="id_submit" name="submit" value="{% trans "Subscribe" %}" type="submit" /></p>
</form>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"></div>
</div>
</div>
{% endblock %}
@dokterbob
Copy link

The form is in the context as newsletter_form, hence you should render {{ newsletter_form.as_p }} instead of {{ form.as_p }}.

@bld2104
Copy link
Author

bld2104 commented Mar 27, 2018

@dokterbob sorry I didn't see this until now, usually GitHub gives me an email when you respond but it didn't so I didn't notice this! I changed it, but we still have the issue of newsletter = Newsletter.objects.get(slug="bla"). What are we trying to match for the slug, the user id or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment