Q:

Django: Form class not working?

Because of the small scale of a website I'm creating, I decided to skip JSON and just create an ajax page which returned actual html or single words saying what to do. There seems to be some error in the code since at new_user_pass = new_user(request.POST) the server suddenly returns 500 (INTERNAL SERVER ERROR) The website checks if the user has loged in before, and then makes a decision: if they have, redirect to the home page after creating a session (yet to be coded). If they have not: Return a word that tells JQuery to ask them for additional information.  If there is an error somewhere, it should get to the end of the file where it returns errors (yet to be completely coded).
This is the forms.py file:
class log_in(forms.Form):
    username = forms.EmailField()
    password = forms.PasswordInput()

class new_user(forms.Form):
    username = forms.EmailField()
    password = forms.PasswordInput()
    password2 = forms.PasswordInput()
    pen_name = forms.CharField(max_length=30)

The views.py file:
def user_log_in(request):
    #add stuff for ajax request
    user_pass = log_in(request.POST)
    er = []
    if user_pass.is_valid():
        cleaned_info = user_pass.cleaned_data
        user_object = User.objects.filter(email = cleaned_info['username'])
        if user_object.exists():
            #create session
            return HttpResponseRedirect('/home')
        else:
            new_user_pass = new_user(request.POST)#where bug is
            cleaned_info = new_user_pass.cleaned_data
            if new_user_pass.is_valid():
                if cleaned_info['password'] == cleaned_info['password2']:
                    new_user = User(activated = 0, email = cleaned_info['username'], pen_name = cleaned_info['pen_name'], password = cleaned_info['password'])
                    new_user.save()
                    msg = ""
                    if send_mail('Activate', msg, '*******', [cleaned_info['username']], fail_silently=False):
                        return HttpResponse('e_act')
                    else:
                        er.append("Error Sending Email")
                else:
                    er.append('Passwords are not the same')
            elif cleaned_info['TN']:
                for e in new_user_pass.errors:
                    er.append(e)
            else:
                return HttpResponse('n_usr')
    return HttpResponse('SOS')

And, though I don't think the error is here, the Jquery function:
n_usr = false;
function log_in () {
    //add code to check if it's the wrong usr, pass, correct, or if they've never logged in before.
    //code to reveal section

Edit: Django gived the error new_user' referenced before assignment

A:

The next fragment is wrong:
def new_user():
    print "in new_user"

def f():
    new_user()
    if True:
        new_user = 23
        print "new_user"

f()

You can't call new_user() because compiler thinks that it is in the scope of the f() because of the farther initialization of new_user.
You use new_user as two different things - as a constructor of the form
new_user(request.POST)

and as a User instance:
new_user = User(activated = 0, email = cleaned_info['username'], pen_name = cleaned_info['pen_name'], password = cleaned_info['password'])

It is also not good in terms of programming style - to use one name for absolutely different variables. 
For example, you can use another name for the local variable and it must be OK:
new_user_inst = User(activated = 0, email = cleaned_info['username'], pen_name = cleaned_info['pen_name'], password = cleaned_info['password'])
...

