Thursday, June 30, 2011

JQuery .load() works in production but fails in development

Hi Folks:

I have to say that I am completely enamored with Django. I have been using it for about a week and it is a really awesome framework!

The problem I have is that JQuery .load() does not work correctly in my development environment on port 8001 ( runserver

It works just fine in my production environment (port 80) which leads me to believe that the the problem is related to the "same origin" policy or some sort of Apache configuration problem but I don't know how to fix it.

I have a very simple example that illustrates what is going on. It is a page that dynamically call /cgi/ script each time the "loadit" link is clicked.

How can I make it work in the development environment? Is there some way to allow apache to handle the CGI calls on port 8001 while Django runserver manages the rest? Is there a better way to do this?

Thank you,


Details follow.

  O/S:      Linux (CentOS 5.5)
  Apache:   2.2.3
  Django:   1.3
  JQuery:   1.6.1
  mod_wsgi: 3.3.3
  Python:   2.7.2

CGI script:
  import cgitb
  import datetime
  now =
  print "Content-Type: text/plain;charset=utf-8"
  print 'Timestamp %s' % (now.strftime("%Y-%m-%d %H:%M:%S"))

template (sync.html):
  {% extends "base.html" %}
  {% block head_title %}{{ title }}{% endblock %}
  {% block content %}
  <script type="text/javascript">
  $(document).ready(function() {
  function getStatus() {
  <div id="status"></div>
  <a href="javascript:getStatus();"> loadit </a>
  {% endblock %}
  from django.shortcuts import render_to_response
  from django.template import RequestContext
  def sync(request):
      return render_to_response('sync.html',
                                {'title':'JQuery .load() Test'},

  <VirtualHost *:80>
    DocumentRoot /opt/mysite/2.0/mysite
    ErrorLog     logs/mysite-server_error.log
    AddHandler   cgi-script .cgi .py
    ScriptAlias /cgi /opt/mysite/2.0/cgi
    <Directory /opt/mysite/2.0/cgi>
      Options Indexes FollowSymLinks
      Order allow,deny
      Allow from all
    Alias /media /opt/mysite/2.0/media
    <Directory /opt/mysite/2.0/media>
      Options Indexes FollowSymLinks
      Order allow,deny
      Allow from all
    Alias /static/admin /opt/python2.7/lib/python2.7/site-packages/django/contrib/admin/media
    <Directory /opt/python2.7/lib/python2.7/site-packages/django/contri/admin/media>
      Options Indexes
      Order allow,deny
      Allow from all
    WSGIScriptAlias / /opt/mysite/2.0/mysite/apache/django.wsi

You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment