Django - 路由到非django脚本? (例如简单的WSGI / CGI应用程序) [英] Django - routing to non-django script? (e.g. simple WSGI/CGI application)
问题描述
如何(如果可能的话)可以在Django中设置一个路由,将路由指向一个非django脚本的某个url?例如。我想通过一个非常简单的CGI脚本(如这个)来处理 / independent
:
How (if it is possible) can set up a route in Django that would point a certain url to a non-django script? E.g. I'd like to have /independent
handled by a very simple CGI script such as this one:
import os
print 'Status: 200 OK'
print 'Content-type: text/html'
print
for key, value in os.environ.items():
print key, ': ', value, '<br/>'
我不是一个Django用户(但是,我认为是在我身上),只需要一个方法来将这个小的绕行转换成一个应用程序。那是这样吗?如果是,如何?
I'm not a Django user (yet, I.. think, it's upon me) and just need a way to hack this little detour into an application. So: is this possible? If yes, how?
推荐答案
不是直接。所有Django网址必须去Django视图,一个可以接受请求并返回响应的callable。
Not directly. All Django urls have to go to a Django view, a callable which accepts a request and returns a response.
您可以将重定向[1]返回到任意URL 。所以你应该能够编写一个非常简单的包装器视图来做你想要的。
You can though return a redirect[1] to an arbitrary urls. So you should be able to write a very simple wrapper view to do what you want.
[1] https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#examples
这篇关于Django - 路由到非django脚本? (例如简单的WSGI / CGI应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!