Note that there are some explanatory texts on larger screens.

plurals
  1. PORequest for new user account via email Django
    text
    copied!<p>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 <a href="http://djangosnippets.org/snippets/261/" rel="nofollow">http://djangosnippets.org/snippets/261/</a> but it is very old and might be inaccurate for I have got and thus I have problems with it.</p> <p>I have this code currently:</p> <h3>account/models.py</h3> <pre><code>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() </code></pre> <h3>account/views.py</h3> <pre><code>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, ['example@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') </code></pre> <h3>urls.py</h3> <pre><code>(r'^thankyou/$', 'account.views.thankyou'), (r'^new_account/$', 'account.views.request_account_view'), </code></pre> <h3>templates/new_account.html</h3> <pre><code>{% extends "base.html" %} {% block content %} &lt;form action="/new_account/" method="post"&gt; {% csrf_token %} &lt;label id="id_first_name"&gt;First Name:&lt;/label&gt; &lt;input type="text" name="first_name" value="" id="first_name" /&gt; &lt;label id="id_last_name"&gt;Last Name:&lt;/label&gt; &lt;input type="text" name="last_name" value="" id="last_name" /&gt; &lt;label id="id_email"&gt;Email:&lt;/label&gt; &lt;input type="text" name="email" value="" id="email" /&gt; &lt;input type="submit" value="Submit Request"/&gt; &lt;/form&gt; {% endblock %} </code></pre> <p>I am getting an error for:</p> <pre><code>Forbidden (403) CSRF verification failed. Request aborted. </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload