def forums(request): if request.method =="POST": form = Forums(request.POST) #validamos el formulario if form.is_valid(): newForum = Forum(request.POST["title"],request.POST["theme"],request.POST["asignature"]) return render(request,'foros.html', {'form': form},context_instance=RequestContext(request)) else: form = Forum() return render(request,'foros.html', {'form': form},)
def showForums(request): com = Forum.objects.all() context = {'forum': com} if request.method == "POST": form = Forums(request.POST) #validamos el formulario if form.is_valid(): newForum = Forum() newForum.title = request.POST["title"] newForum.theme = request.POST["theme"] newForum.asignature = request.POST["asignature"] newForum.save() return redirect("/foros") else: form = Forum() return render(request, 'foros.html', {'forum': com, 'form': form})
def showForums(request): com = Forum.objects.all() context = {'forum': com} if request.method =="POST": form = Forums(request.POST) #validamos el formulario if form.is_valid(): newForum = Forum() newForum.title = request.POST["title"] newForum.theme = request.POST["theme"] newForum.asignature = request.POST["asignature"] newForum.save() return redirect("/foros") else: print form.errors else: form = Forum() return render(request,'foros.html', {'forum': com,'form': form})
def showForums(request): #obtenemos todos los foros com = Forum.objects.all() context = {'forum': com} #si se hace un POST, se crea el formulario para añadir foro if request.method =="POST": form = Forums(request.POST) #validamos el formulario if form.is_valid(): newForum = Forum() newForum.title = request.POST["title"] newForum.theme = request.POST["theme"] newForum.asignature = request.POST["asignature"] #guardamos los datos del foro newForum.save() return redirect("/foros") else: print form.errors #si no se hace POST, se crea el foro y se renderiza la página donde se muestran los foros else: form = Forum() return render(request,'foros.html', {'forum': com,'form': form})