Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Contact form doesn't see user as logged in [RSS Feed]

#1 Jan. 4, 2011 01:28:08

C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Contact form doesn't see user as logged in


I am having trouble with a contact form on my site. Whenever I hit
the page, it doesn't see that the user is logged in. Here's how my
code looks.

------------
#forms.py

from django import forms
from django.utils.translation import ungettext, ugettext_lazy as _

class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required=False)
message =
forms.CharField(widget=forms.Textarea(attrs={'rows':'20',
'cols':'75'}))
------------


------------
#urls.py
from django.conf.urls.defaults import *

urlpatterns = patterns('myproject.forms.views',
(r'^contact-us/$', 'contact'),
)
------------


------------
#views.py

from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from myproject.forms.forms import ContactForm

def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
send_mail(
cd,
cd+'\nUser email '+cd,
('formemailaddr...@email.com'),
,
)
return HttpResponseRedirect('/forms/thanks/')
else:
form = ContactForm()
return render_to_response('forms/contact.html', {'form': form})
------------


If I hit another page, the user still shows up as being logged in,
just this one area (the contact form) doesn't. Even the thank you page
shows the user as being logged in.

Anyone have any ideas?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@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.

Offline

#2 Jan. 4, 2011 07:38:50

Łukasz R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Contact form doesn't see user as logged in


On 4 January 2011 02:27, Catalyst <cataly...@gmail.com> wrote:
>  I am having trouble with a contact form on my site. Whenever I hit
> the page, it doesn't see that the user is logged in. Here's how my
> code looks.

How do you check that user is logged in ? If it's via request.user,
then it doesn't work 'cause you
aren't passing the request object to your template's context. The
recomended way to do this is using RequestContext:

from django.template import RequestContext

return render_to_response('forms/contact.html', {'form': form},
context_instance=RequestContext(request))

>
> ------------
> #forms.py
>
> from django import forms
> from django.utils.translation import ungettext, ugettext_lazy as _
>
> class ContactForm(forms.Form):
>    subject = forms.CharField()
>    email = forms.EmailField(required=False)
>    message =
> forms.CharField(widget=forms.Textarea(attrs={'rows':'20',
> 'cols':'75'}))
> ------------
>
>
> ------------
> #urls.py
> from django.conf.urls.defaults import *
>
> urlpatterns = patterns('myproject.forms.views',
>    (r'^contact-us/$', 'contact'),
> )
> ------------
>
>
> ------------
> #views.py
>
> from django.core.mail import send_mail
> from django.http import HttpResponseRedirect
> from django.shortcuts import render_to_response
> from myproject.forms.forms import ContactForm
>
> def contact(request):
>    if request.method == 'POST':
>        form = ContactForm(request.POST)
>        if form.is_valid():
>            cd = form.cleaned_data
>            send_mail(
>                cd,
>                cd+'\nUser email '+cd,
>                ('formemailaddr...@email.com'),
>                ,
>            )
>            return HttpResponseRedirect('/forms/thanks/')
>    else:
>        form = ContactForm()
>    return render_to_response('forms/contact.html', {'form': form})
> ------------
>
>
>  If I hit another page, the user still shows up as being logged in,
> just this one area (the contact form) doesn't. Even the thank you page
> shows the user as being logged in.
>
>  Anyone have any ideas?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>



--
Łukasz Rekucki

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@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.

Offline

#3 Jan. 4, 2011 07:44:31

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Contact form doesn't see user as logged in


On Tue, 2011-01-04 at 08:38 +0100, Łukasz Rekucki wrote:
> How do you check that user is logged in ? If it's via request.user,
> then it doesn't work 'cause you
> aren't passing the request object to your template's context. The
> recomended way to do this is using RequestContext:
>
> from django.template import RequestContext
>
> return render_to_response('forms/contact.html', {'form': form},
> context_instance=RequestContext(request))

and add the context processor:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
)


--
regards
KGhttp://lawgon.livejournal.comCoimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@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.

Offline

#4 Jan. 4, 2011 09:47:32

C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Contact form doesn't see user as logged in


Thank you, this worked. I appreciate the fast response Łukasz.

On Jan 3, 11:38 pm, Łukasz Rekucki <lreku...@gmail.com> wrote:
> On 4 January 2011 02:27, Catalyst <cataly...@gmail.com> wrote:
>
> >  I am having trouble with a contact form on my site. Whenever I hit
> > the page, it doesn't see that the user is logged in. Here's how my
> > code looks.
>
> How do you check that user is logged in ? If it's via request.user,
> then it doesn't work 'cause you
> aren't passing the request object to your template's context. The
> recomended way to do this is using RequestContext:
>
> from django.template import RequestContext
>
> return render_to_response('forms/contact.html', {'form': form},
> context_instance=RequestContext(request))
>
>
>
>
>
> > ------------
> > #forms.py
>
> > from django import forms
> > from django.utils.translation import ungettext, ugettext_lazy as _
>
> > class ContactForm(forms.Form):
> >    subject = forms.CharField()
> >    email = forms.EmailField(required=False)
> >    message =
> > forms.CharField(widget=forms.Textarea(attrs={'rows':'20',
> > 'cols':'75'}))
> > ------------
>
> > ------------
> > #urls.py
> > from django.conf.urls.defaults import *
>
> > urlpatterns = patterns('myproject.forms.views',
> >    (r'^contact-us/$', 'contact'),
> > )
> > ------------
>
> > ------------
> > #views.py
>
> > from django.core.mail import send_mail
> > from django.http import HttpResponseRedirect
> > from django.shortcuts import render_to_response
> > from myproject.forms.forms import ContactForm
>
> > def contact(request):
> >    if request.method == 'POST':
> >        form = ContactForm(request.POST)
> >        if form.is_valid():
> >            cd = form.cleaned_data
> >            send_mail(
> >                cd,
> >                cd+'\nUser email '+cd,
> >                ('formemailaddr...@email.com'),
> >                ,
> >            )
> >            return HttpResponseRedirect('/forms/thanks/')
> >    else:
> >        form = ContactForm()
> >    return render_to_response('forms/contact.html', {'form': form})
> > ------------
>
> >  If I hit another page, the user still shows up as being logged in,
> > just this one area (the contact form) doesn't. Even the thank you page
> > shows the user as being logged in.
>
> >  Anyone have any ideas?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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.
>
> --
> Łukasz Rekucki

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@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.

Offline

  • Root
  • » Django
  • » Contact form doesn't see user as logged in [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support