基于django的迷你框架:importd

jopen 10年前發布 | 11K 次閱讀 importd Web框架

受 Sinatra 啟發基于Django的微型框架。完全兼容django。

Django很棒,但利用它開始開發一個新的項目是痛苦的。importd受來自ruby的sinatra啟發。
Hello world django project:

from importd import d
d(DEBUG=True)

@d("/") def idx(request): return "index.html"

@d("/post/<int:post_id>/") def post(request, post_id): return "post.html", {"post_id": post_id}

if name == "main": d.main()</pre>

To run it:

$ python foo.py

This will start the debug server.

To run it in production:

$ gunicorn foo:d

特性

  • fully compatible with django
  • supports smarturls
  • most of regularly used django functions and classes available in d. namespace, eg d.HttpResponse, d.render_to_response, d.get_object_or_404 etc
  • automatically maps "templates" folder in foo.py directory to serve templates
  • automatically maps "static" folder in foo.py to serve static content
  • management commands still available: $ python foo.py shell
  • wsgi compliant
  • gunicorn support
  • works seamlessly with fhurl (http://packages.python.org/fhurl/)
  • Auto Add django-debug-toolbar (Needs to add it manually to INSTALLED_APPS)
  • Auto SECRET_KEY: If no SECRET_KEY on settings, try to read SECRET_KEY from ./secret.txt , if no ./secret.txt generate a random string then write it to ./secret.txt and finally return it as SECRET_KEY.
  • Auto Add coffin/django-jinja (jinja2 integration)

項目主頁:http://www.baiduhome.net/lib/view/home/1416295591102

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!