Python Django Web Application issue
Question: I have created a user creation page and forget password page. all the fields
are created in models.py and i want to show the forgot password through
HttpResponse when the user clicks of submit button forgot password page.
Please help how to get it.

    
    
    models.py as in my project
    from django.db import models
    
    # Create your models here.
    class NewUser(models.Model):
        fname=models.CharField(max_length=12)
        lname=models.CharField(max_length=15)
        address=models.TextField()
        email=models.EmailField(max_length=50)
        pwd=models.CharField(max_length=12)
        cpwd=models.CharField(max_length=12)
        cell=models.CharField(max_length=10)
    def __unicode__(self):
        return self.email
    
    views.py as in my project
    def forgot_pwd(request):
    if request.method=='POST':
        #import pdb; pdb.set_trace()
        email_id=request.POST.get('userid','')
        print email_id
        rec_mail_id=NewUser.objects.get(email=email_id)
        print rec_mail_id
        if rec_mail_id:
            rec_pwd=NewUser.objects.get(pwd)
            return HttpResponse("Your password is %s" %rec_pwd)
        else:
            return HttpResponse("You are not yet registered\n   <a href=/CreateUser>Please click here to register</a>")
    else:
            return render_to_response('forgot_pwd.html', context_instance=RequestContext(request))
    


Answer: `models.py` should be :

    
    
    class user_registration(models.Model):
        email_id = models.EmailField(max_length=500,blank=False)
        password = models.CharField(max_length=500,null=True)
    

`views.py` should be :

def checkRegistration(request):

    
    
    if request.method == 'GET':
        form = ContactForm(request.GET)
        if form.is_valid():
            email = form.cleaned_data['email_id']
            getpassword = user_registration.objects.get(email_id=email)
            print getpassword.password
            "Manuculate with getpassword as you want"
    
    else:
         "Do whatever you want"
    

`form.py` should be :

    
    
    from django.forms import ModelForm
    from models import data
    
    
    class ContactForm(ModelForm):
        class Meta:
            model = user_registration
            fields = [
                      "email_id",
                      "password"
                      ]
    

