aamalig / django-profile

Automatically exported from code.google.com/p/django-profile
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Django 1.2 with csrf : "You cannot alter upload handlers after the upload has been processed." on avatar upload #82

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. using the demo 
2. activate the csrf middleware.
3. Go to /accounts/profile/edit/avatar/
3. Upload an image from disk.
4. You cannot alter upload handlers after the upload has been processed.

* What is the expected output? What do you see instead?
"You cannot alter upload handlers after the upload has been processed."

Traceback:
File "/home/moodball/lib/python2.5/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/moodball/lib/python2.5/django/contrib/auth/decorators.py" in 
_wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File "/home/moodball/webapps/django/mb/userprofile/views.py" in avatarchoose
  227.         request.upload_handlers.insert(0, QuotaUploadHandler())
File "/home/moodball/lib/python2.5/django/utils/datastructures.py" in complain
  425.             raise AttributeError(self.warning)

Exception Type: AttributeError at /accounts/profile/edit/avatar/
Exception Value: You cannot alter upload handlers after the upload has been 
processed.

* What version of the product are you using? On what operating system?

django-profile SVN
Django 1.2 with CSRF activated
Python 2.5 / 2.6 

Original issue reported on code.google.com by alph...@gmail.com on 17 Jun 2010 at 4:53

GoogleCodeExporter commented 8 years ago
A solution (well quick fix) after reading the doc :
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
"
Note
You can only modify upload handlers before accessing request.POST or 
request.FILES -- it doesn't make sense to change upload handlers after upload 
handling has already started. If you try to modify request.upload_handlers 
after reading from request.POST or request.FILES Django will throw an error.

Thus, you should always modify uploading handlers as early in your view as 
possible.
"

Original comment by alph...@gmail.com on 17 Jun 2010 at 5:02

Attachments: