reauest.session[] not working.

24 views
Skip to first unread message

Nigel Legg

unread,
Oct 30, 2013, 9:44:42 AM10/30/13
to django...@googlegroups.com
My view:

@login_required
def list(request):
    user = User.objects.get(pk=request.session['user.id'])
    # Handle file upload
    if request.method == 'POST':
        form = dataFileForm(request.POST, request.FILES)
        if form.is_valid():
            newdat = dataFiles(datafile = request.FILES['datafile'])
            newdat.user_id = user
            newdat.save()
            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('tilda.myapp.views.list'))
    else:
        form = dataFileForm() # A empty, unbound form'''
    # Load documents for the list page
    datafiles = dataFiles.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'myapp/list.html',
        {'datafiles': datafiles, 'form': form, },
        context_instance=RequestContext(request)
    )

Under Windows7, using Python 2.7.5, with MySQL, this works after login, showing a list of files already uploaded and the form to upload a new file. 
I have now moved the app onto Ubuntu 13.04, using Python 2.7.4 with Postgres 9.1 (in reparation for a test deployment to Heroku), using vrtualenv.  Following login, when I try and access this page, I get: Key Error at myapp/list: 'user.id'.
I cant find a reason for this not working, can anyone help?

 

Cheers, Nigel
07914 740972

Tom Evans

unread,
Oct 30, 2013, 9:59:19 AM10/30/13
to django...@googlegroups.com
On Wed, Oct 30, 2013 at 1:44 PM, Nigel Legg <nigel...@gmail.com> wrote:
> My view:
>
> @login_required
> def list(request):
> user = User.objects.get(pk=request.session['user.id'])

What is putting this 'user.id' key in the session? d.c.auth puts
"_auth_user_id" in the session (but if the 'user' is the logged in
user, why any of this, why not request.user?)

Cheers

Tom

Nigel Legg

unread,
Oct 30, 2013, 11:14:20 AM10/30/13
to django...@googlegroups.com

I'll try that, but why does this work under windows and not ubuntu

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1%2BqLWiu2Q9aATFD9A7uM5ahkuE7CNJdNiQ%2BdwLqQwXYOg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages