NameError: global name 'UserProfile' is not defined
<pre><code># getting error while i am running my register user code
</code></pre>

<p><a href="http://i.stack.imgur.com/QBzxZ.png" rel="nofollow">enter image description here</a></p>

<pre><code>from django.shortcuts import render
from .forms import *
from django.core.context_processors import csrf
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
import hashlib, datetime, random
from django.contrib import auth
from django.core.mail import send_mail
from django.contrib.auth import authenticate, login

# Create your views here.

def index(request):
    return render(request,'app/index.html')
def register_user(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        args['form'] = form
        if form.is_valid(): 
            form.save()  # save user to database if form is valid

            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]            
            activation_key = hashlib.sha1(salt+email).hexdigest()            
            key_expires = datetime.datetime.today() +   datetime.timedelta(2)

            #Get user by username
            user=User.objects.get(username=username)

            # Create and save user profile                                                                                                                                  
            new_profile = UserProfile(user=user, activation_key=activation_key, 
                key_expires=key_expires)
            new_profile.save()

            # Send email with activation key
            email_subject = 'Account confirmation'
            email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \
            48hours http://127.0.0.1:8000/confirm/%s" % (username, activation_key)

            send_mail(email_subject, email_body, 'myemail@example.com',
                [email], fail_silently=False)

            return render(request,'app/success',{})
    else:
        args['form'] = RegistrationForm()

    return render_to_response('app/register.html', args, context_instance=RequestContext(request))
</code></pre>

<p>You must have created class <code>UserProfile</code> in your models.py. You need to import this into your views to get the code working. </p>

python django