Suffer Less By Using Django Dev Server as a Proxy

Suffer Less By Using Django Dev Server as a Proxy,第1张

Suffer Less By Using Django Dev Server as a Proxy - Irrational Exuberance

Suffer Less By Using Django Dev Server as a Proxy


When doing web development, you'll occasionally run into a situation where you are developing a new user interface or otherwise redesigning a website, but either cannot or don't want to tear out the existing pieces you are replacing. Maybe the tyrannical IT department has to approve all reboots for the development server, or your new project is a quick prototype down a different line of thought and you don't want to devote time to replacing the current system before the prototype proves its value.

As it often does, Django steps in as a handy tool in this situation. With some minimal customization you can use the Django development server to serve certain urls patterns and transparently proxy the remainder to another server.

Why?
  1. For development, the Django development server is a real boon. It isn't quick, but it's quick enough, and its automatic reboots on code changes really speeds up development.

  2. You can transparently develop above an existing platform. This is especially true when building JavaScript heavy applications relying upon a RESTful api (because you are implementing new functionality on the client-side, and with your thoughtfully designed api you won't need to make changes to the server-side of the application).

    In particular, this approach allows you to use XMLHttpRequest-based
    Ajax functionality cross-domain without your browser slapping your hand and saying no. This works because you're requesting the URL locally,
    the proxy is fetching it from the remote host, and finally it is being returned to the requester it as if it all occurred locally.

    This also means that
    when you do integrate your new UI/feature into the existing application, you won't need to change any of the urls.

  3. Don't need admin access (or ability/know-how to build) the
    main server. You don't have to wait for the server to reboot,
    caches to clear, or settings to reset.

How?

Using Django as a proxy is quite simple. First you'll need to install Django and Httplib2:

curl http://www.djangoproject.com/download/1.0/tarball/ > Django-1.0.tar.gz
tar xzvf Django-1.0.tar.gz
cd Django-1.0
sudo python setup.py install
sudo easy_install httplib2

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2089368.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存