I want to create a directory structure like 开发者_如何学Pythonthe following. How can I get the account.py and game.py to handle the requests that go to \account\ and \game\ respectfully. All the app-engine examples I have seen have all the logic in on main.py that handle all urls.
app\account\
\account.py
\game\
\ game.py
\static\css
\js
\images
\app.yaml
\main.py
I tried the following in app.yaml but it didn't work
application: mefirst
version: 1
runtime: python
api_version: 1
handlers:
- url: /static
static_dir: static
- url: /account
script: account.py
- url: .*
script: main.py
You need the following in your app.yaml
:
- url: /account
script: account/account.py
- url: /game
script: game/game.py
- url: .*
script: main.py
BTW, I suggest you try to forget backslashes (characters like this: \ ) -- think normal slashes (characters like this: / ). Backslashes are a Windows anomaly (and mostly unneeded even there -- Python will happily accept normal slashes in lieu of backslashes in filepaths), not used as path separators in URLs nor on Unix-y operating systems (including Linux and MacOSX). I mention this because you speak of "requests that go to \account\ and \game\ respectfully" and there are no such things -- no request goes to a path with backslashes, it will always be forward slashes.
Take a look at MVCEngine, a framework for AppEngine that provides a Ruby on Rails-like structure for building apps. It may or may not be overkill for what you are looking to do, but if you take a look in the main project file, MVCEngine.py, you should be able to see how it goes about providing for a project directory structure somewhat like you want. It's not too difficult.
精彩评论