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 (manage.py runserver 0.0.0.0:8001).
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/getstatus.py 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,
Joe
Details follow.
Setup:
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:
#!/opt/python2.7/bin/python2.7
import cgitb
import datetime
cgitb.enable()
now = datetime.datetime.now()
print "Content-Type: text/plain;charset=utf-8"
print
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() {
getStatus();
});
function getStatus() {
$('#status').load('/cgi/getstatus.py');
}
</script>
<div id="status"></div>
<a href="javascript:getStatus();"> loadit </a>
{% endblock %}
views.py:
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'},
context_instance=RequestContext(request))
httpd.conf:
<VirtualHost *:80>
ServerAdmin me@example.com
ServerName mysite-server.example.com
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
</Directory>
Alias /media /opt/mysite/2.0/media
<Directory /opt/mysite/2.0/media>
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
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
</Directory>
WSGIScriptAlias / /opt/mysite/2.0/mysite/apache/django.wsi
</VirtualHost>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Xd7Av3nuf6AJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment