選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.py 1.2 KiB

12年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import sys, os
  2. sys.path.extend([".", "app", "lib"])
  3. from werkzeug.wrappers import Request, Response
  4. from werkzeug.local import LocalManager
  5. from werkzeug.wsgi import SharedDataMiddleware
  6. import mimetypes
  7. import webnotes
  8. import webnotes.handler
  9. import webnotes.auth
  10. import webnotes.webutils
  11. local_manager = LocalManager([webnotes.local])
  12. @Request.application
  13. def application(request):
  14. webnotes.local.request = request
  15. webnotes.init()
  16. webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
  17. for k, v in (request.form or request.args).iteritems() })
  18. webnotes.local._response = Response()
  19. try:
  20. webnotes.http_request = webnotes.auth.HTTPRequest()
  21. except webnotes.AuthenticationError, e:
  22. pass
  23. if webnotes.form_dict.cmd:
  24. webnotes.handler.handle()
  25. else:
  26. webnotes.webutils.render(webnotes.request.path[1:])
  27. return webnotes._response
  28. application = local_manager.make_middleware(application)
  29. application = SharedDataMiddleware(application, {
  30. '/': os.path.join(os.path.dirname(__file__), "..", "..", "public")
  31. })
  32. if __name__ == '__main__':
  33. import sys
  34. from werkzeug.serving import run_simple
  35. run_simple('localhost', 8000, application, use_reloader=True,
  36. use_debugger=True, use_evalex=True)