> What about passing a variable set to False ? Should I still pass it
> like so :
> return render(request,'index.html', {'form': form,
> 'has_account':False})
> Or is it useless to pass it ?

Since you hardcode it to be False, yes it useless also to check in the template.

If the variable is missing a "if" in the template will evaluate to False.

If the template is used by other views which could provide has_account =True it 
should be in there, of course!



> 
> 
> On Nov 23, 5:02 am, DrBloodmoney <drbloodmo...@gmail.com> wrote:
>> On Tue, Nov 22, 2011 at 6:54 PM, Nolhian <eldur...@hotmail.com> wrote:
>>> Hello,
>> 
>>> I've got a subscription form and this view :
>> 
>>> def index(request):
>>>        c = RequestContext(request)
>>>        if request.user.is_authenticated():
>>>                return render_to_response('index.html', {'has_account': 
>>> True})
>>>        if request.method == 'POST':
>>>                form = SignupForm(request.POST,error_class=DivErrorList)
>>>                if form.is_valid():
>>>                        return HttpResponseRedirect('/thanks/')
>>>        else:
>>>                form = SignupForm()
>>>        return render_to_response('index.html', {'form': form, 'has_account':
>>> False}, c)
>> 
>>> 1) In Index.html I have a form with a {% csrf_token %}. If I don't put
>>> c = RequestContext(request) and add the c into every
>>> render_to_response I've got a csrf error. Is my view above the right
>>> way to handle csrf ?
>> 
>>> 2) I noticed that instead putting
>>> c = RequestContext(request) *at the beginning of my view*
>>> and :
>>> return render_to_response('index.html', {'form': form, 'has_account':
>>> False}, c) *at the end of my view*
>> 
>>>  I could just put this at the end of my view :
>> 
>>> c = RequestContext(request, {'has_account': False,'form': form})
>>> return render_to_response('index.html', c)
>> 
>>> Which one it the best approach ?
>> 
>>> 3) I also noticed that if i don't pass 'has_account': False to my
>>> template, nothing changes, it still evaluate it as false in {% if
>>> has_account %}. Is it best to pass it to the template anyway ?
>> 
>>> Thanks in advance,
>> 
>>> Nolhian
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=en.
>> 
>> Just use the render [1] shortcut. It'll put the RequestContext in for you.
>> 
>> [1]https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to