出于某种原因,我的模型表单未显示在我的模板中
以前使用的是完全相同但现在它不起作用? 是否有人可以帮助我,我被困了几个星期,真的想要提前我的HTML代码
{% extends "navbar.html" %}
{% load static %}
{% block content%}
<div class="alert alert-danger" role="alert"><B>Let op!</b> Deze website is nog maar een testversie en kan niet altijd aan de eisen voldoen
</div>
<div class="col-md-6 col-md-offset-3">
speciaal voor ivo, dus het werkt wel gewoon... of toch niet
{{form}}
</div>
{% endblock %}
form.py
from django import forms
from .models import Trainingen
class TrainingenForm(forms.ModelForm):
class Meta:
model = Trainingen
fields = ['Klasse', 'Locatie', 'Datum']
models.py
from django.db import models
#create your models here
class Trainingen(models.Model):
Klasse = models.CharField(max_length=120)
Locatie = models.CharField(max_length=120)
Datum = models.CharField(max_length=120)
def __unicode__(self):
return self.Klasse
vieuws.py
from django.shortcuts import render
from .forms import TrainingenForm
from .models import trainingen
# your views here.
def trainingen(request):
form = TrainingenForm(request.POST or None)
context = {
"form": form
}
if form.is_valid():
instance = form.save(commit=False)
instance.save()
return render(request, "Trainingen.html" , context)