Have some trouble with displayed form via web.
I'm using Django 1.6.2
In forms.py
from django import forms
class ContactForm(forms.Form):
pk_post = forms.CharField(max_length=1, required=False)
user_post = forms.CharField(max_length=20, required=False)
description_post = forms.CharField(max_length=200, required=False)
In views.py
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.http import HttpResponse
from report.models import Main, Data
from report.forms import ContactForm
from django.template import RequestContext, loader
def index(request):
mainc = Data.objects.all()
template = loader.get_template('report/index.html')
context = RequestContext(request, {
'mainc': mainc,
})
return HttpResponse(template.render(context))
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
pk_post = form.cleaned_data['pk_post']
user_post = form.cleaned_data['user_post']
description_post = form.cleaned_data['description_post']
p = Main.objects.get(pk=pk_post)
p.data_set.all()
p.data_set.create(user=user_post, description=description_post, data_date=timezone.now())
In index.html i'm added next code:
<form action="" method="post">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit">
</form>
But when I load index.html via browser I can see only "Submit" button. Table from {{ form.as_table }} not generated.