I sent detail on a new post "why form cant save""
در چهارشنبه 29 مهٔ 2019، ساعت 3:52:30 (UTC+4:30)، Saeed Pooladzadeh نوشته:
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/c07d404a-0208-4e9a-8693-f4002b92f785%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment