Okay. Thank you so very much! Just one last question, just to know that i
got it right. So, variables and return are not part of the else clause, and
that they return the errors of the last form post. Did i got it right?


On Fri, Jul 12, 2013 at 8:41 PM, Daniel Roseman <dan...@roseman.org.uk>wrote:

> On Friday, 12 July 2013 14:27:31 UTC+1, Kakar wrote:
>
>> Okay! That did solved the problem. Thank you! Here's my new view.py:
>>
>> def register_page(request):
>>     if request.method == 'POST':
>>         form = RegistrationForm(request.POST)
>>         if form.is_valid():
>>             user = User.objects.create_user(
>>                 username=form.cleaned_data['**username'],
>>                 email=form.cleaned_data['**email'],
>>                 password=form.cleaned_data['**password1']
>>                 )
>>             return HttpResponseRedirect('/**register/success/')
>>
>>     else:
>>         form = RegistrationForm()
>>     variables = RequestContext(request,{
>>             'form':form
>>             })
>>     return render_to_response('**registration/register.html',**variables)
>>
>> I am just a noob with these things. I understood why the first instance
>> didn't worked, but can u please explain to me about the indentation part
>> (variables and return)? I am little bit puzzled in here. And don't the
>> second 'if' require an else?
>> Thanks again!
>>
>
> Well, presumably you understand that in Python, indentation defines blocks
> for things like if and for. If there's no else clause for an if, Python
> will resume execution at the next line that is indented at the same level
> as the beginning of the if statement. In this case, there isn't one,
> because the surrounding block - ie the first if statement - is complete.
> So, it's going to skip over the else clause belonging to the outer if, and
> carry on at the first line at that level - which now is the one starting
> with `variables`.
>
> The upshot of all this is that if the form is not valid, it will skip
> right down to the bottom and execute those last two lines, which render the
> template with the invalid form, and return it.
> --
> DR.
>
> --
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to