我在GAE构建了一个前端用PHP,后端用Python的应用程序。我想用Python编写完整的应用程序,但我不知道如何开始。你知道吗
在当前的PHP应用程序中,我设置了一个.htaccess文件,将每个请求(图像、JavaScript等除外)重写为索引.php. 在索引.php我将根据请求路径包含正确的页面(php)文件。你知道吗
每页所需的所有文件都存储在“page”文件夹中,文件名与url的布局匹配。你知道吗
下面的代码是一个开始,但我认为它提供了一个想法,我的方向。你知道吗
import sys
def main(environ, start_response):
dirs = environ['PATH_INFO'].split('/')
params = {}
action = []
for dir in dirs:
if dir.count('='):
param = dir.split('=')
params[param[0]] = param[1]
elif dir:
action.append(dir)
try:
# get the right module (the code per page)
page_module = 'pages.'+'.'.join(action)
__import__(page_module)
page = sys.modules[page_module]
page_return_function = getattr(page, 'response')
except:
return 'PAGE NOT FOUND'
html_return = ''
html_return += page_return_function(environ, start_response)
return html_return
我面临的最大问题是我想使用“webapp2”,因为它嵌入在GAE中,可以处理很多事情(会话等)。你知道吗
希望我已经解释清楚我的问题,我真的很感谢你的帮助。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐