目前,我正在使用 mod_wsgi 在服务器上开发 python 应用程序。但是,应用程序会很大,非常大,我的问题如下:
如何在 mod_wsgi(urls, localhost/login route 等) 上做一个好的路由系统。通常,我这样做是:
urls = [
(r'^$', index),
(r'hello/?$', hello),
(r'hello/(.+)$', hello)
]
def application(environ, start_response):
"""
The main WSGI application. Dispatch the current request to
the functions from above and store the regular expression
captures in the WSGI environment as `myapp.url_args` so that
the functions from above can access the url placeholders.
If nothing matches call the `not_found` function.
"""
path = environ.get('PATH_INFO', '').lstrip('/')
for regex, callback in urls:
match = re.search(regex, path)
if match is not None:
environ['myapp.url_args'] = match.groups()
return callback(environ, start_response)
return not_found(environ, start_response)
现在,我在想......如果我在那里写每条路线,python 文档将有成千上万的代码行。它会让它变慢吗?
不要因为我不喜欢而写框架,我想从头开始。