views:

286

answers:

4

Hi all,

I just want to ask a simple question, as I don't imagine how to do it.

In the app.yaml, when I want to declare query string parameter, how do I do it?

For example, to make a multi language site, I create the url in this format:

mysite.com/english/aboutus

mysite.com/italiano/aboutus

and in app.yaml the script to handle them are

- url: /english/aboutus
  script: index.py

- url: /italiano/aboutus
  script: index.py

In which way can I determine the difference between these two urls, and how to handle them in index.py?

I know this is simple question, I could look around for references, but it might help for others in stackoverflow.com as well.

+2  A: 

Instead you could use the webapp framework to handle the URL's.

For example, in index.py

application = webapp.WSGIApplication(
                                 [('/english', EnglishHandler)],
                                 [('/italiano', ItalianHandler)],
                                 debug=True)

More information can be found here. http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html

Ryan Kearney
Hi Ryan, how about other pages as well? It seems not very clear to me your solution. for example, I have products page, services page, contacts page, all in two languages?
sfa
+1  A: 

The SCRIPT_NAME environ entry contains the path under which your script was invoked. Haven't tested this in GAE specifically, but it's something WSGI inherited from CGI.

language= environ['SCRIPT_NAME'][1:].split('/', 1)[0]
if language not in ('english', 'italiano'):
    language= 'english'
bobince
Hi bobince, your solution seems to be complexed if there are many urls.I read somewhere that we can use the regular expressions but I have not immagined how to do it :-s
sfa
? What are you trying to do, exactly? Adding more pages doesn't change the code at all, I'm not sure why you think you might need a regex?
bobince
Hi bobince, in this case, you have to handle the script_name manually with some switch/cases, etc... for example, it might occur a null reference, you have to check as well. by doing a regular expression, it is easier I think ;) please correct me if I am wrong :)
sfa
Now I'm lost! Python doesn't have any `switch`/`case` construct, `SCRIPT_NAME` can't be `None`, and you can choose what page to show with simple string matching (no need for regex). Perhaps you'd be better off using an existing web framework with support for dispatching requests to different handlers?
bobince
Hi bobince, sorry I have not tested your code before commenting on the last one :-DYour code works well except that 'SCRIPT_NAME' is changed to 'PATH_INFO', and environ is os.environlanguage= os.environ['PATH_INFO'][1:].split('/', 1)[0]Thank you!
sfa
+3  A: 

I remember doing something like this:

in app.yaml put

- url: /(.*)/(.*)/?
  script: main.py

and in main.py

class MainHandler(webapp.RequestHandler):
     def get(self, Urlpart1, Urlpart2):

def main():
     application = webapp.WSGIApplication([('/(.*)/(.*)/', MainHandler),
                                         ('/(.*)/(.*)', MainHandler)], 
                                         debug=True)

where Urlparts are words between slashes

Chris
A: 

There're 39 human languages supported. Best way seems comply via lib/django/django/conf/locale/ Here's an app that translates all engines messages via parameter hl=[languageCode] [code disposable][2]

LarsOn