Django form fields don't appear in my html render page
i have a problem in my django project. Im quite new and im try to create a base form to create a new item in my database.
this is forms.py
from django import forms
from .models import Progetto
class Myprogetto(forms.ModelForm):
class Meta:
model = Progetto
fields = ['nome', 'descrizione', 'data_inizio', 'data_fine']
this is my views.py
from django.shortcuts import render,redirect
from .models import Progetto
from django.http import JsonResponse, HttpResponseRedirect
from .forms import Myprogetto
def aggiungi_progetto(request):
if request.method == "POST":
form = Myprogetto(request.POST)
if form.is_valid():
nome = form.cleaned_data['nome']
Myprogetto_object=form.save(commit=False)
Myprogetto_object.save()
return HttpResponseRedirect("/thanks/")
else:
form = Myprogetto()
return render(request, 'lista_progetti.html', {"form": form})
this is my lista_progetti.html
<form id="popUpForm" display="none" action="" method="post"> {% csrf_token %} {{ form.as_p }} <input type="submit" value="Salva"> </form>
the problem is that when i lauch the server the form appear empty with just the button <salva>. I added a screenshot. my form view in html render
Anyone can help me?
Thank you
i tried to use both forms.ModelForm class and forms.Form class but the result is the same. I also try to write a simple form in html using html syntax and the fields appears but then i have problems in django to send the data to database cause it ask me to put the csrf_token.