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 %}
    <form action="/new_account/" method="post">
    {% csrf_token %}
        <label id="id_first_name">First Name:</label>
        <input type="text" name="first_name" value="" id="first_name" /
>
        <label id="id_last_name">Last Name:</label>
        <input type="text" name="last_name" value="" id="last_name" />
        <label id="id_email">Email:</label>
        <input type="text" name="email" value="" id="email" />
        <input type="submit" value="Submit Request"/>
    </form>
    {% 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.

Reply via email to