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['subject'], > > cd['message']+'\nUser email '+cd['email'], > > ('formemailaddr...@email.com'), > > ['sendaddr...@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 at http://groups.google.com/group/django-users?hl=en.