On Wednesday, May 18, 2011 2:16:00 PM UTC+1, Michel30 wrote:
>
> Hey all, 
>
> I have a Django 1.3 app that retrieves user credentials from LDAP. 
> Most views require the user to be authenticated so I use the 
> @login_required decorator. 
>
> Now, in a form a user can upload a document using a form: 
>
> <form action="." method="post" enctype="multipart/form-data">{% 
> csrf_token %} 
> {{ form }} 
> <input type="submit" value="Create new CM item"> 
> </form> 
>
> I want to log the user's first and lastname who submitted the file in 
> a model. So, in my view I've tried a number of solutions but all came 
> up with various errors either related to the @login_required decorator 
> or complaining that no user exists in the POST object. 
>
> This is the latest attempt I have in my view: 
>
> def home(request): 
>     form = SimpleFileForm() 
>     if request.method == 'POST': 
>         if 'upload_file' in request.FILES: 
>             upload_file = request.FILES['upload_file'] 
>             filename = request.FILES['upload_file'].name 
>             user = request.user 
>             firstname = user.first_name 
>             lastname = user.last_name 
> etc... 
>
> It throws this error: 'unicode' object has no attribute 'user' 
>
> Does someone know a good way how to do this? (Any suggestions on how 
> to get rid of the file textfield / browse button and only leave a 
> submit button to open a select dialog are also very much appreciated) 
>
> Thanks, 
> Michel 
>

That is the correct way to do it. I don't think that is the real code you're 
running, because `request` is clearly not a unicode object in the line 
beginning with `filename`, and yet it is one line later.

The full traceback would help, as would the actual code.

I don't know what you mean by "a submit button to open a select dialog".
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to