开发者

Submitting a Form to a Django Server is Really Slow

I have a webpage that looks like:

<html>
  <head>
    <title>Hi</title>
  </head>
  <body>
    <form name="mainForm" method="post" action="">
      <p>
        <input type="checkbox" name="PLD">
        <input type="submit" value="Submit">
      </p>
    </form>
  </body>
</html>

If the checkbox is not checked, form submission works in both FF and IE. However, if the checkbox is checked, it takes about two minutes to give a response in either browser! With Chrome, the form submission works even when the checkbox is checked.

I have never seen a problem like this before, so I think the problem is with my Django server (it's running through Apache 2.2.9-10 on开发者_开发问答 Debian Linux). In my Apache log, I occasionally see errors like:

[Sun Jul 25 17:45:05 2010] [error] [client X.X.X.X] mod_wsgi (pid=30418): Exception occurred processing WSGI script '/X/django.wsgi'., referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X] Traceback (most recent call last):, referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]   File "/var/lib/python-support/python2.5/django/core/handlers/wsgi.py", line 231, in __call__, referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]     set_script_prefix(base.get_script_name(environ)), referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]   File "/var/lib/python-support/python2.5/django/core/handlers/base.py", line 199, in get_script_name, referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]     return force_unicode(environ.get('SCRIPT_NAME', u'')), referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]   File "/var/lib/python-support/python2.5/django/utils/encoding.py", line 68, in force_unicode, referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X]     s = s.decode(encoding, errors), referer: X
[Sun Jul 25 18:45:06 2010] [error] [client X.X.X.X] LookupError: no codec search functions registered: can't find encoding, referer: X

This error doesn't always happen. I've searched around, but I don't know what it means.

I have tried using a DOCTYPE for the webpage, and using a META tag to set the content type charset as utf-8 or iso-8859-1. None of these helped.

Does anybody have any idea what's going on here? Thanks!

The Django code looks like:

def page(request):
  return HttpResponse("""
<html>
  <head>
    <title>Hi</title>
  </head>
  <body>
    <form name="mainForm" method="post" action="">
      <p>
        <input type="checkbox" name="PLD">
        <input type="submit" value="Submit">
      </p>
    </form>
  </body>
</html>
""")


I can't even image the reason behind abnormally slow responses but fixing encoding errors is easy. Apache doesn't run with unicode locale in debian by default. Write following line in your apache envvars file (from django wiki):

export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

BTW your view code is weird.


By the way, for anyone who cares, I solved this issue by making a very large length (a few KB long) hidden field inside the form. I have no idea why that fixed things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜