The new form that I'm trying to make is the one with the variable: form, I forgot to mention that
On Friday, January 25, 2019 at 10:08:03 AM UTC-5, Arturo Fernandez wrote: > > Hello, I'm trying to make a simple form so I can dissect it and learn but > from the guide that I'm reading, they are doing it differently from what > I'm trying to accomplish. This are the two links: > > model.py: https://tutorial.djangogirls.org/en/django_models/ > view.py, forms.py: https://tutorial.djangogirls.org/en/django_forms/ > > Just for the sake of learning I copied pasted those codes, now... she's > trying to create multiple pages in that tutorial, one for create and one > for edit but I only want to have 1 page which I have created, it's my > profile page, and there I want to edit it whether it's empty or not and > save it. > > If I do it like this in my view.py (which is where the error is happening): > > > @login_required > def profile(request): > if request.method == 'POST': > u_Passform = PasswordChangeForm(request.user, request.POST) > u_form = UserUpdateForm(request.POST, instance=request.user) > p_form = ProfileUpdateForm(request.POST, > request.FILES, > instance=request.user.profile) > > > form = PostForm(request.POST, instance=post) > > if u_form.is_valid() and p_form.is_valid() and u_Passform.is_valid() and > form.is_valid(): > u_Passform.save() > u_form.save() > p_form.save() > > post = form.save(commit=False) > post.author = request.user > post.save() > > update_session_auth_hash(request, u_Passform) > messages.success(request, f'Your account has been updated!') > > return redirect('profile') > > else: > form = PostForm(instance=post) > u_Passform = PasswordChangeForm(request.user) > u_form = UserUpdateForm(instance=request.user) > p_form = ProfileUpdateForm(instance=request.user.profile) > > context = { > 'form': form, > 'user_AddressForm': AddressForm, > 'u_Passform': u_Passform, > 'u_form': u_form, > 'p_form': p_form > } > > return render(request, 'users/profile.html', context) > > > it says: UnboundLocalError: local variable 'post' referenced before > assignment > > the error I think that is basically on the form declaration right? how can > I get the data from the form? I created an admin section for it and I see > that the form data was saved there, but how can I display it on the view? > Note: the profile.html works fine, it's just the view.py the one with the > problem I think. > > Thanks guys > > > > -- 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+unsubscr...@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/c2258e02-798d-4778-84d3-db8686712506%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.