我正在尝试使用Django Crisy Form在灯箱中建立联系表单。但是,我无法使布局或css工作,因为原始html格式的结果相同。我附上下面的代码,并欣赏如果有人可以建议如何使其工作。非常感谢。
Models.py:
from django.db import models
# Create your models here.
class db_contact(models.Model):
Date = models.DateTimeField ('Date')
Name = models.CharField ('Name', max_length = 50)
Subject = models.DateField ('Subject', max_length = 20)
Email = models.CharField ('Email', max_length = 200)
Message = models.CharField ('Message', max_length = 50000)
def __str__(self):
return self.Subject
class Meta:
ordering = ['id']
Forms.py
from django import forms
from django.forms import ModelForm
from siteapps.models import db_contact
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit
class frm_contact(ModelForm):
def __init__(self, *args, **kwargs):
super(frm_contact, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_id = 'id-exampleForm'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
self.helper.form_action = 'submit_survey'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = db_contact
fields = ['Name', 'Subject', 'Email', 'Message']
views.py
def contact(request):
form_contact = frm_contact()
return render(request, 'contact.html', {'form_contact' : form_contact})
contact.html
{% extends request.is_ajax|yesno:"fancybox/base.html,main.html" %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block content %}
{% crispy form_contact form_contact.helper %}
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="xxx"></div>
{% endblock %}
答案 0 :(得分:0)
当我找到解决方案时,我将回答我的问题。
事实证明我错过了引导程序js / css,现在它可以与bootstrap3一起使用。
答案的更多细节可以在这里找到: Django crispy forms not loading CSS