'tuple' object has no attribute 'update'
Question: I'd like to extend my user profiles using custom models. Unfortunately
whenever I'm visiting the page where the profile is located I receive 'tuple'
object has no attribute 'update'

I've tried to get around this myself but after 2,5hrs it did hit me that I'm
stuck.

Could anyone enlighten me please?

Model:

    
    
    from django.db import models
    from django.contrib.auth.models import User
    
    # Create your models here.
    
    class Skills(models.Model):
    description = models.CharField(max_length=3000)
    
    class UserProfile(models.Model):
    
    #Choices
    STAFF = (
        ('AD', 'Super User'),
        ('MA', 'Manager'),
    )
    DEPT = (
        ('TD', 'Tech Service'),
        ('CS', 'Customer Service'),
    )
    user = models.OneToOneField(User, blank=False, unique=True)
    staff = models.CharField(max_length=2, choices=STAFF)
    dept = models.CharField(max_length=3, choices=DEPT)
    team = models.BooleanField(default=False)
    skill = models.ManyToManyField(Skills)
    email = models.EmailField()
    
    User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
    

forms

    
    
    from django import forms
    from models import UserProfile
    
    class UserProfileForm(forms.ModelForm):
    
    class Meta:
        model = UserProfile
        fields = ('staff', 'dept', 'team', 'skill', 'email')
    

view

    
    
    from django.shortcuts import render_to_response
    from django.http import HttpResponseRedirect
    from django.core.context_processors import csrf
    from forms import UserProfileForm
    from django.contrib.auth.decorators import login_required
    
    @login_required
    def user_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts')
    else:
        user = request.user
        profile = user.profile
        form = UserProfileForm(instance=profile)
    
    args = ()
    args.update(csrf(request))
    
    args['form'] = form
    
    return render_to_response(profile.html, args)
    

app urls.py

    
    
    from django.conf.urls import patterns, include, url
    
    urlpatterns = patterns('',
        url(r'^profile/$', 'userprofile.views.user_profile'),
        )
    

and standard urls.py

    
    
    from django.conf.urls import patterns, include, url
    
    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'tms_core.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('userprofile.urls')),
    )
    

Finally the traceback:

    
    
    Environment:
    
    
    Request Method: GET
    Request URL: http://127.0.0.1:8000/accounts/profile/
    
    Django Version: 1.6.1
    Python Version: 2.7.5
    Installed Applications:
    ('django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'userprofile')
    Installed Middleware:
    ('django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware')
    
    
    Traceback:
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
      22.                 return view_func(request, *args, **kwargs)
    File "/home/user/projects/tms5/tms_core/userprofile/views.py" in user_profile
      20.     args.update(csrf(request))
    
    Exception Type: AttributeError at /accounts/profile/
    Exception Value: 'tuple' object has no attribute 'update'
    

Also, I'm running this project in a virtual env.

Any help would be appreciated.


Answer: In your view `args` should be dict not tuple:

    
    
    # args = ()
    args = {}
    

