我已经在PHP中构建了一个带有前端的应用程序,并在Python中构建了Python的后端应用程序。我想用Python完成我的完整应用程序,但我不知道如何开始。
在当前的PHP应用程序中,我设置了一个.htaccess文件来将每个请求(图像,JavaScript等排除)重写为index.php。在index.php中,我根据请求路径包含右页(php)文件。
每页所需的所有文件都存储在文件夹“页面”中,文件名与网址布局相符。
下面的代码是一个开始,但我认为它可以让我了解自己的目标。
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中,它处理很多事情(会话等)。
希望我已经清楚地解释了我的问题,非常感谢你的帮助。