Реализация проверки электронной почты в Django

Я создал приложение Django. У меня есть страница регистрации (простая HTML-форма) в приложении, и на ней есть поле для электронной почты при регистрации. Теперь я хотел реализовать проверку электронной почты при регистрации пользователя. Например, отправка электронного письма пользователю (на адрес электронной почты, указанный в регистрационной форме). Путем поиска в Google я обнаружил, что есть метод Django send_email, который можно использовать для вышеуказанного. Но, будучи новичком в Django, я не мог понять, какие изменения и функции должны быть созданы для этого.Может ли кто-нибудь помочь мне в этом или указать какие-нибудь уроки, которые могли бы мне помочь. Или есть другой способ реализовать это, кроме метода send_email в Django. Любая помощь будет принята с благодарностью

Я вставлю сюда свои нынешние коды.

VIEWS.PY

def registrationForm(request):
    if request.method == "POST":  
        firstName = request.POST.get("firstName")
        lastName = request.POST.get("lastName")
        email = request.POST.get("email")
        password = request.POST.get("password")
        sex = request.POST.get("sex")
        birthday = request.POST.get("birthday")
        print request.POST.get("sex")
        UniversityDetails(firstName=firstName,lastName=lastName,email=email,password=password,sex=sex,birthday=birthday).save()
        return render_to_response('registrationForm.html')
    return render_to_response("registrationForm.html")

def login(request):
    if request.POST:            
        email=request.POST.get("username")
        password = request.POST.get("password")
        print email
        print password
        user = UniversityDetails.objects.filter(email=email,password=password)
        print user
        if(not user):
            return render_to_response("registrationForm.html",{'invalid': True })
        else:
            return render_to_response("login.html")
    return render_to_response("registrationForm.html")

registrationForm.html

<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

  <script>
  $(document).ready(function() {
    $("#datepicker").datepicker();
  });
  </script>
</head>

<title>
Login/Registration Page
</title>

    <script type="text/javascript">

   //Created / Generates the captcha function    
    function DrawCaptcha()
    {
        var a = Math.ceil(Math.random() * 10)+ '';
        var b = Math.ceil(Math.random() * 10)+ '';       
        var c = Math.ceil(Math.random() * 10)+ '';  
        var d = Math.ceil(Math.random() * 10)+ '';  
        var e = Math.ceil(Math.random() * 10)+ '';  
        var f = Math.ceil(Math.random() * 10)+ '';  
        var g = Math.ceil(Math.random() * 10)+ '';  
        var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
        document.getElementById("txtCaptcha").value = code
    }

    // Validate the Entered input aganist the generated security code function   
    function ValidCaptcha(){
        var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2) return true;        
        return false;

    }

    // Remove the spaces from the entered and generated code
    function removeSpaces(string)
    {
        return string.split(' ').join('');
    }

    </script>
<body onload="DrawCaptcha();">

<div align="center">
<form name="userInputForm" method="POST" id="myFormid" action="http://10.1.0.90:8080/login/">
<div style="float:left;width:100%;">
  <p style="float:left;margin-right:10px;width:auto;"><label style="float:left;">Email id</label><br/> <input type="text" name="username" size="25" /></p>
  <p style="float:left;margin-right:10px;width:auto;"><label style="float:left;">Password</label><br/><input type="password" name="password" size="25" />

{% if invalid %}
    Mismatch in your email/password. 
{% endif %}

</p>

 </div> 
    <p style="clear:both;float:left;"><input type="submit" value="Log in" /></p> 
</div>
</form><
<script type="text/javascript">
function userCheck(){
    /*document.getElementById('myFormid').action = "http://10.1.0.90:8080/login/";
    if ((document.userInputForm.username.value.length==0)) */
}
</script>
<form name ="myform"  method="POST" id='FormID'>
<table>
<tr>
<td>First name</td>
<td>
<input type="text" name="firstName" value=""  maxlength="100" />
<b id="firstNameID" style="font-family:Times New Roman;color:#B4045F;font-size:14px;">
</td>
</tr>

<tr>
<td>Last name</td>
<td>
<input type="text" name="lastName" value="" maxlength="100" />
</td>
</tr>

<tr>
<td>E-mail</td>
<td>
<input type="text" name="email" value="" maxlength="100" />
</td>
</tr>
<tr>
<td>Password</td>
<td>
<input type="password" name="password" value="" maxlength="100"  />
<b id="passwordID" style="font-family:Times New Roman;color:#B4045F;font-size:14px;">
</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" name="sex" value="male" /> Male
<input type="radio" name="sex" value="female" /> Female
</td>
</tr>
<tr>
<td>Birthday</td>
<td>
<input type="text" name="birthday" id='datepicker' value="" maxlength="100" />
</td>
</tr>
</tr>
</table>
<table>
<tr>
    <td>

    </td>
</tr>
<tr>
    <td>
        <input type="text" id="txtCaptcha" 
            style="background-image:url(1.jpg); text-align:center; border:none;
            font-weight:bold; font-family:Modern" />
        <input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" />
    </td>
</tr>
<tr>
    <td>
        <input type="text" id="txtInput"/>    
    </td>

<td> <br> <br>
<input type="button" value="Sign Up" onClick="isEmpty();"/>
</td>
</tr>
</table>
<script type="text/javascript">
function isEmpty(){
    if  ((document.myform.firstName.value.length==0)) 
        {
        document.getElementById('firstNameID').innerHTML = 'Please fill this field';
        return true;
        }
    else if ((document.myform.password.value.length==0)) 
        {
        document.getElementById('passwordID').innerHTML = 'Please fill this field';
        return true;
        }
    else if (! ValidCaptcha())
        {
            alert("Captcha entered wrong");
        }

    else 
        { 
        document.getElementById('FormID').action = "http://10.1.0.90:8080/registrationForm/";
        document.getElementById('FormID').submit();
        return false; 
        }
}
</script>
</body>


</html>
10
задан rv_k 31 March 2011 в 04:25
поделиться