I have Django 0.95 up and running with no problems under Apache2 with
flatpages installed and also running fine.
I have limited uploads by adding the setting LimitRequestBody 5242880
to the httpd.conf file, which works great. If I try to upload a large
file I get this in the error.log:
[Fri Dec 01 11:08:28 2006] [error] [client 127.0.0.1] Requested
content-length of 8627377 is larger than the configured limit of
5242880, referer: http://127.0.0.1/doc/create/
I want Apache to send the user to a nice error page if this happens.
So, I created a nice error page using flatpages with the url:
/413error/
I tested it by typing in: http://127.0.0.1/413error/ in the address bar
of the browser and I get the nice error message.
The next thing I did was set: ErrorDocument 413 /413error/ in the
httpd.conf file hoping that Apache would send the user to the desired
URL but I get a message in Firefox stating: "The connection to the
server was reset while the page was loading."
I also tried a simple ErrorDocument 413 "The file is too big" and this
did not work either.
I'm tapped out, could someone please give me a hint as to what I am
missing here?
Thanks in advance.
PS I have been restarting Apache after every change to the httpd.conf
file.
References:
http://httpd.apache.org/docs/trunk/mod/core.html#errordocument
http://httpd.apache.org/docs/trunk/mod/core.html#limitrequestbody
My additions to httpd.conf for Django:
# Changed MaxRequestsPerChild 0 to 1 for Django
<IfModule mpm_winnt.c>
ThreadsPerChild 250
MaxRequestsPerChild 1
</IfModule>
Alias /media/ "C:/idms_project/idms/media/"
<Location "/media/">
SetHandler None
</Location>
ErrorDocument 413 /413error/
LimitRequestBody 5242880
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "['C:\idms_project'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE idms.settings
PythonDebug On
</Location>
I think the question should be...
How do I handle the 413 error within Django?
Any help would be greatly appreciated.
As long as YOURTEMPLATE correctly renders a template you created to
display the error message (perhaps with context), that should do the
trick. You may find the code for other error codes interesting as well [2].
[1]:
http://www.djangoproject.com/documentation/request_response/#httpresponse-objects
[2]:
http://code.djangoproject.com/browser/django/trunk/django/http/__init__.py
It appears that when I configure Apache to limit the request body, if a
file is uploaded that exceeds the setting, Apache doesn't seem to pass
on anything to mod_python and records an error in error.log. Thus the
view never gets called so there is no opportunity to raise the error in
the view.
It seems that mod_python interferes with the mechanism that Apache uses
when one configures the ErrorDocument setting. The user gets a message
from the browser saying that the connection was dropped.
Does anyone know how to get hold of this error message so that a *nice*
message can be sent to the user? Are there any other options?