使用Foundation 6的Django 1.10表单字段不显示在模板中

时间:2017-01-01 17:49:11

标签: django django-forms zurb-foundation-6

我正在尝试在Django中构建一个简单的登录页面,允许用户注册电子邮件简报。我正在使用这个cookie切割器模板 - https://github.com/Parbhat/cookiecutter-django-foundation - 因为它整合了Jump 6中的Foundation。

挑战在于表单字段未显示在模板中。任何帮助将不胜感激。

我的models.py是:

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

我的forms.py是:

from django import forms
from .models import Subscribe

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

我的views.py是:

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)

我的模板是:

{% 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>

我的urls.py是:

# -*- 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'),

]

谢谢!

1 个答案:

答案 0 :(得分:0)

我使用您的代码创建了应用程序并且它有效。

https://github.com/hvlads/Foundation

申请名称 - blin