def edit_profile(request): avatars = [request.build_absolute_uri(reverse('static', kwargs={'path': 'avatars/%s_32.png' % av})) for av in ('waffle', 'smiley', 'Frank', 'Pete', 'necktie', 'blueberry_puzzled', 'orange_with-it', 'watermelon_grumpy', 'strawberry_happy')] try: profile = request.user.get_profile() except Profile.DoesNotExist: profile = Profile(user=request.user) profile.avatar = avatars[0] if request.method == 'POST': form = ProfileForm(request.POST, instance=profile) if form.is_valid(): form.save() request.flash.put(message="Your changes have been saved.") return HttpResponseRedirect(reverse('home')) else: form = ProfileForm(instance=profile) return render_to_response( 'registration/edit_profile.html', { 'profile_form': form, 'current_avatar': form.initial['avatar'], 'avatar_choices': avatars, }, context_instance=RequestContext(request), )