다음과 같은 간단한 코드가 있지만 getjson이 어떻게 작동합니까? 파이썬 스크립트가 json으로 인코딩 된 값을 올바르게 인쇄합니다. 누구든지 추천 할 수 있습니까?파이썬 스크립트를 호출 할 때 getJson은 작동하지 않습니다.
HTML
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$.getJSON('weather.py', function(data) {
console.log('callback works');
});
</script>
</body>
</html>
파이썬 :
import json
from json import load
from urllib2 import urlopen
from pprint import pprint
import pycassa
from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily
from pycassa.index import *
pool = pycassa.ConnectionPool('hr')
crime = pycassa.ColumnFamily(pool, 'crime')
##Pull all of the data and convert to JSON
data = json.dumps([columns for key, columns in crime.get_range()])
return data
감사합니다. 웹 서버의 예 또는 어떻게 구현할 수 있습니까? – Ataman
http://docs.python.org/2/howto/webservers.html 사용해보기 – Jharwood