Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1927976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:55:26+00:00 2026-05-17T06:55:26+00:00

I get a Must be a User Instance error message. TRACEBACK Traceback: File /Library/Python/2.6/site-packages/django/core/handlers/base.py

  • 0

I get a Must be a User Instance error message.

TRACEBACK

Traceback:
File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/Users/ApPeL/Sites/Django/omu2/../omu2/friends/views.py" in add
  13.         if form.is_valid():
File "/Library/Python/2.6/site-packages/django/forms/forms.py" in is_valid
  120.         return self.is_bound and not bool(self.errors)
File "/Library/Python/2.6/site-packages/django/forms/forms.py" in _get_errors
  111.             self.full_clean()
File "/Library/Python/2.6/site-packages/django/forms/forms.py" in full_clean
  234.             value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
File "/Library/Python/2.6/site-packages/django/forms/widgets.py" in value_from_datadict
  170.         return data.get(name, None)

Exception Type: AttributeError at /friends/add/
Exception Value: 'User' object has no attribute 'get'

views.py

from friends.forms import InviteFriendForm, UserForm
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import Http404, HttpResponseRedirect
from django.contrib.auth.models import User

def add(request, template_name='friends/add.html'):
    if request.method == 'POST':
        from_user = request.user
        user = request.user

        form = InviteFriendForm(UserForm, from_user, user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')

    else:
        form = InviteFriendForm(UserForm)

    context = { 'form':form, }

    return render_to_response(template_name, context,
        context_instance=RequestContext(request))

forms.py

class UserForm(forms.Form):

    def __init__(self, user=None, *args, **kwargs):
        self.user = user
        super(UserForm, self).__init__(*args, **kwargs)


if EmailAddress:
    class JoinRequestForm(forms.Form):

        email = forms.EmailField(label="Email", required=True, widget=forms.TextInput(attrs={'size':'30'}))
        message = forms.CharField(label="Message", required=False, widget=forms.Textarea(attrs = {'cols': '30', 'rows': '5'}))

        def clean_email(self):
            # @@@ this assumes email-confirmation is being used
            self.existing_users = EmailAddress.objects.get_users_for(self.cleaned_data["email"])
            if self.existing_users:
                raise forms.ValidationError(u"Someone with that email address is already here.")
            return self.cleaned_data["email"]

        def save(self, user):
            join_request = JoinInvitation.objects.send_invitation(user, self.cleaned_data["email"], self.cleaned_data["message"])
            user.message_set.create(message="Invitation to join sent to %s" % join_request.contact.email)
            return join_request


class InviteFriendForm(UserForm):

    to_user = forms.CharField(widget=forms.HiddenInput)
    message = forms.CharField(label="Message", required=False, widget=forms.Textarea(attrs = {'cols': '20', 'rows': '5'}))

    def clean_to_user(self):
        to_username = self.cleaned_data["to_user"]
        try:
            User.objects.get(username=to_username)
        except User.DoesNotExist:
            raise forms.ValidationError(u"Unknown user.")

        return self.cleaned_data["to_user"]

    def clean(self):
        to_user = User.objects.get(username=self.cleaned_data["to_user"])
        previous_invitations_to = FriendshipInvitation.objects.invitations(to_user=to_user, from_user=self.user)
        if previous_invitations_to.count() > 0:
            raise forms.ValidationError(u"Already requested friendship with %s" % to_user.username)
        # check inverse
        previous_invitations_from = FriendshipInvitation.objects.invitations(to_user=self.user, from_user=to_user)
        if previous_invitations_from.count() > 0:
            raise forms.ValidationError(u"%s has already requested friendship with you" % to_user.username)
        return self.cleaned_data

    def save(self):
        to_user = User.objects.get(username=self.cleaned_data["to_user"])
        message = self.cleaned_data["message"]
        invitation = FriendshipInvitation(from_user=self.user, to_user=to_user, message=message, status="2")
        invitation.save()
        if notification:
            notification.send([to_user], "friends_invite", {"invitation": invitation})
            notification.send([self.user], "friends_invite_sent", {"invitation": invitation})
        self.user.message_set.create(message="Friendship requested with %s" % to_user.username) # @@@ make link like notification
        return invitation
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:55:27+00:00Added an answer on May 17, 2026 at 6:55 am

    Please try this

    def add(request, user_id,template_name='friends/add.html'):
         if request.method == 'POST':
             user = get_object_or_404(User, pk=user_id)
    
             form = InviteFriendForm(request.user, request.POST)
             if form.is_valid():
                 form.save()
                 return HttpResponseRedirect('/')
    
         else:
             form = InviteFriendForm()
    
         context = { 'form':form, }
    
         return render_to_response(template_name,
    context,
    context_instance=RequestContext(request))text_instance=RequestContext(request))
    

    request.user is the sender. and the sender is call in the form. you dont need to declare the from.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get an SqlDateTime overflow error (Must be between 1/1/1753 12:00:00 AM and 12/31/9999
I'm migrating a webapp to python 2.7 with GAE and this error message appears:
I'm trying to understand REST. Under REST a GET must not trigger something transactional
My Java code must get string HH:MM from console and needs to operate with
I have an app that must get data from the Sqlite database in order
if i click on any checkbox all previous checkboxes must get checked my logic
I'm making an insert statement, the id field has auto_increment, another field must get
I'm trying to build a switch and I get an expression must have integral
I get from another class string that must be converted to char. It usually
I must be missing something obvious here... I can't get .change() to fire on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.