def laddaUppBild(request): if request.method == 'POST': # If the form has been submitted... form = BildForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass titel = form.cleaned_data['titel'] nyBild = Bilder(titel=titel) nyBild.save() return HttpResponseRedirect(reverse('minapp.views.index'))# Redirect after POST else: form = BildForm() # An unbound form return render_to_response('laddaUppBild.html', locals())
def addPic(request): valdTitel = request.POST['titel'] valdFil = request.POST['fil'] newPic = Bilder(titel = valdTitel, file = valdFil) newPic.save() return HttpResponseRedirect('/')