Django 1.10 Form Fields Using Foundation 6 Not Showing In Template

261 Views Asked by At

I am trying to build a simple landing page in Django that will allow users to sign up for an email newsletter. I am using this cookie cutter template - https://github.com/Parbhat/cookiecutter-django-foundation - because it integrates Foundation 6 from the jump.

The challenge is that the form fields are not showing in the template. Any help would be appreciated.

My models.py is:

class Subscribe(models.Model):
    email = models.EmailField()
    subscription_status = models.BooleanField(default=True)
    create_date = models.DateTimeField(auto_now_add = True, auto_now = False)
    update_date = models.DateTimeField(auto_now_add = False, auto_now = True)

    def __unicode__(self):
        return self.email

My forms.py is:

from django import forms
from .models import Subscribe

class SubscribeForm(forms.ModelForm):
    class Meta:
        model = Subscribe
        fields = ('email',)

My views.py is:

from django.shortcuts import render

from subscribers.forms import EmailForm, SubscribeForm
from .models import Subscribe


def home(request):

    form = SubscribeForm(request.POST or None)
    if form.is_valid():
        new_join = form.save(commit=False)
        #we might need to do something here.
        email = form.cleaned_data['email']
        new_join_old, created = Subscribe.objects.get_or_create(email=email)
        #new_join.save()

    context = {"form": form}
    template = "pages/home.html"
    return render(request, template, context)

And my template is:

{% extends "base.html" %}

{% load foundation_formtags %}
{% block content %}


    <section class="hero">
    <!-- HERO SECTION -->
        <div class="homebox">
            <div class="wrap">
                <p>Lorem Ipsum</p>
                <form class="form" method="post" action=""> {% csrf_token %}
                    {{ form|as_foundation }}
                    <input type='submit' value='Subscribe' class='btn' />
                </form>
            </div>
        </div>  
    </section>

My urls.py is:

# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.conf.urls import url

from . import views
from subscribes.views import home

urlpatterns = [
    url(r'^$', home, name='home'),

]

Thanks!

0

There are 0 best solutions below