Can you please send the screenshot or text of error. Also, try - form.save(commit=False)
On Wed, 29 May 2019, 04:53 Saeed Pooladzadeh, <lingo1357@gmail.com> wrote:
--HiI'm trying to make a simple crud applicatio and learn from it. I wonder why my form can't save the data. Here cames my view:
from django.shortcuts import renderfrom saeed.forms import SmodelFormfrom saeed.models import Smodelfrom django.shortcuts import render, redirect# Create your views here.def emp(request):if request.method == "POST":form = SmodelForm(request.POST)if form.is_valid():try:form.save()return redirect('/show')except AssertionError as error:print(error)passelse:form = SmodelForm()return render(request,'saeed/index.html',{'form':form})#----------------------------------------def show(request):smodels = Smodel.objects.all()return render(request,'saeed/show.html',{'smodels':smodels})#----------------------------------------def edit(request, id):smodels = Smodel.objects.get(id=id)return render(request,'saeed/edit.html', {'smodels':smodels})#-------------------------------------------def update(request, id):smodels = Smodel.objects.get(id=id)form = SmodelForm(request.POST, instance = smodels)if form.is_valid():form.save()return redirect("/show")return render(request,'saeed/edit.html',{'smodels':smodels})#---------------------------------------------def destroy(request, id):smodels = Smodel.objects.get(id=id)smodels.delete()return redirect("/show")
and here cames the complete app:can you please inform me where is wrong?thanksthanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83aa34e2-2da1-432d-94ba-ec0beea90608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAC3mK7fp6Nwj%3DBOk9psELGEKDbYPr2oNHhPe5ohLDSrEvAcWJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment