我有一個可以正常工作的應用程序。我試圖讓其中一個腳本只在用戶是管理員(我)時才運行。管理員登錄工作正常,但後來我重定向到頁面/地理編碼,什麼也沒有發生。我看到200的HTTP響應。以管理員身份登錄後腳本無法運行,但如果不需要管理員,則工作正常
有什麼建議嗎?
謝謝
編輯2:要求添加完整的代碼。
的app.yaml:
application: theapp
version: 1
runtime: python
api_version: 1
handlers:
- url: /geocode
script: geocode.py
login: admin
- url: /admin/.*
script: $PYTHON_LIB/google/appengine/ext/admin
login: admin
- url: /favicon\.ico
static_files: static/images/favicon.ico
upload: static/images/favicon\.ico
- url: /static
static_dir: static
- url: /.*
script: first.py
secure: never
builtins:
- appstats: on
inbound_services:
- warmup
first.py:
import os
from beer import Beer
from desktop import Desktop
from geocode import Geocode
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
application = webapp.WSGIApplication(
[('/', Desktop),
('/beer', Beer),
('/geocode', Geocode)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
geocode.py:
import pubs
import os
import time
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp import util
from google.appengine.api import urlfetch
import urllib
import urllib2
import simplejson
class Geocode(webapp.RequestHandler):
'''Class for ./geocode
A couple of methods to take the address' from the Pubs.pub_address array
and turn them into usefull Latitudes & Longitudes.
'''
def get_lat_long(self, location):
place = urllib.quote_plus(location)
print location
url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=true®ion=no" % (place)
print url
out = urllib.urlopen(url)
jsonResponse = simplejson.load(out)
pub_location = jsonResponse.get('results')[0].get('geometry').get('location')
lat = pub_location.get('lat')
lng = pub_location.get('lng')
return lat, lng
def get(self):
pub_address = []
pub_bounce = []
self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
path = os.path.join(os.path.dirname(__file__), 'templates')
path = os.path.join(path, 'geocode.html')
for i, element in enumerate(pubs.pub_list):
pub_bounce.append(pubs.pub_list[i].pub_bounce)
for i, element in enumerate(pubs.pub_list):
pub_address.append(pubs.pub_list[i].pub_address.encode('utf-8'))
for i, element in enumerate(pub_address):
pubs.pub_list[i].pub_lat, pubs.pub_list[i].pub_lng = self.get_lat_long(pub_address[i])
print pubs.pub_list[i].pub_lat, pubs.pub_list[i].pub_lng
time.sleep(.2)
template_values = {"pub_address": pub_address, "pub_bounce": pub_bounce}
self.response.out.write(template.render(path, template_values))
不應該登錄/ geocode登錄:需要而不是管理員? – 2012-01-03 16:46:10
您可以提供關於/ geocode工作的任何東西嗎? – 2012-01-03 16:47:50
/geocode從數據模型中獲取一些地址並將其轉換爲經緯度。正如我所提到的,如果/ geocode的處理程序被移除,它可以正常工作。 「login:admin」適用於已登錄和管理員的用戶。 「login:required」似乎僅適用於已登錄的任何用戶。 – Gareth 2012-01-03 18:12:34