Re: Request for new user account via email Django

2011-08-05 Thread Sheogora
There was a different problem actually,
RequestContext(request) was never called

I removed that line and put it in the above return.
Worked fine :)
thank you for the effort tho

On Aug 4, 5:58 pm, Shawn Milochik  wrote:
> In your view you should be instantiating the form with the data from
> request.POST instead of reading the values directly.
>
> Also, you mention that you get a 403 error when you post your name and
> password, but the form and template you pasted don't include password,
> so I suspect the error is coming from elsewhere.

-- 
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.



Re: Request for new user account via email Django

2011-08-04 Thread Shawn Milochik
In your view you should be instantiating the form with the data from 
request.POST instead of reading the values directly.


Also, you mention that you get a 403 error when you post your name and 
password, but the form and template you pasted don't include password, 
so I suspect the error is coming from elsewhere.



--
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.



Request for new user account via email Django

2011-08-04 Thread Sheogora
I am trying to make a little function for a user to request an account
and the information he puts in is sent to a person who will make an
account.
I was following this example mostly http://djangosnippets.org/snippets/261/
but it is very old and might be inaccurate for I have got and thus I
have problems with it.

I have this code currently:


###account/models.py

from django import forms
from django.core.mail import send_mail, BadHeaderError

# A simple contact form with four fields.
class NewAccountForm(forms.Form):
first_name = forms.CharField()
last_name = forms.CharField()
email = forms.EmailField()

###account/views.py

from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from account.models import NewAccountForm
from django import forms
from django.core.mail import send_mail, BadHeaderError

def request_account_view(request):
first_name = request.POST.get('first_name', '')
last_name = request.POST.get('last_name', '')
email = request.POST.get('email', '')
message = (first_name + ' ' + last_name + '  has requested a new
account for the email ' + email)
if first_name and last_name and email:
try:
send_mail('Request for Account', 
message, email,
['exam...@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header 
found.')
return HttpResponseRedirect('/thankyou/')
else:
return render_to_response('new_account.html', {'form':
NewAccountForm()})

return render_to_response('new_account.html', {'form':
NewAccountForm()},
RequestContext(request))

def thankyou(request):
return render_to_response('thankyou.html')

###urls.py

(r'^thankyou/$', 'account.views.thankyou'),
(r'^new_account/$', 'account.views.request_account_view'),

###templates/new_account.html

{% extends "base.html" %}
{% block content %}

{% csrf_token %}
First Name:

Last Name:

Email:



{% endblock %}

I am getting an error for:

Forbidden (403)
CSRF verification failed. Request aborted.

which occurs after I input name and password and click submit.
My email host is working fine because I previously was working on a
"Forgot Password"
function.
I would really appreciate help. Thank you.

-- 
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.