网址.py
from django.conf.urls import patterns, include, url
import os.path
from crm.views import *
urlpatterns += patterns('',
(r'^test/$', tView.as_view()),
)
视图.py
from django.views.generic import TodayArchiveView
from crm.forms import *
from crm.models import *
class tView(TodayArchiveView):
model = WorkDailyRecord
context_object_name = 'workDailyRecord'
date_field = 'date'
month_format = '%m'
template_name = "onlyWorkDailyRecord.html"
form_class = WorkDailyRecordForm ################## ADD
tView 是通用视图.... WorkDailyRecord 在 models.py 中定义模型
我想将表单(forms.py中的'WorkDailyRecordForm'类)传递给模板(onlyWorkDailyRecord.html)
如何??
添加
表格.py
from django import forms
class WorkDailyRecordForm(forms.Form):
contents = forms.CharField(label='',
widget=forms.Textarea(attrs={'placeholder': 'contents', 'style':'width:764px; height:35px;'}),
required=False,
)
target_user = forms.CharField(label='',
widget=forms.TextInput(attrs={'placeholder': 'target', 'style':'width:724px'}),
required=False,
)
onlyWorkDailyRecord.html
<form method="post" action="." class="form-inline" id="save-form">
{{ form.as_table }}
<button type="submit" class="btn btn-mini" id="workDailyRecord-add">작성</button>
</form>