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

58 行
1.5 KiB

  1. import sys, os
  2. sys.path.extend(["..", "../app", "../lib"])
  3. from werkzeug.wrappers import Request, Response
  4. from werkzeug.local import LocalManager
  5. import mimetypes
  6. import webnotes
  7. import webnotes.handler
  8. import webnotes.auth
  9. import webnotes.webutils
  10. local_manager = LocalManager([webnotes.local])
  11. @Request.application
  12. def application(request):
  13. path = os.path.join("public", request.path[1:])
  14. if os.path.exists(path) and not os.path.isdir(path) and not path.endswith(".py"):
  15. with open(path, "r") as static:
  16. content = static.read()
  17. response = Response()
  18. response.data = content
  19. response.headers["Content-type"] = mimetypes.guess_type(path)[0]
  20. return response
  21. else:
  22. webnotes.local.request = request
  23. webnotes.init()
  24. webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
  25. for k, v in (request.form or request.args).iteritems() })
  26. webnotes.local._response = Response()
  27. try:
  28. webnotes.http_request = webnotes.auth.HTTPRequest()
  29. except webnotes.AuthenticationError, e:
  30. pass
  31. # cookies
  32. print request.form
  33. if webnotes.form_dict.cmd:
  34. webnotes.handler.handle()
  35. else:
  36. webnotes.webutils.render(webnotes.request.path[1:])
  37. return webnotes._response
  38. application = local_manager.make_middleware(application)
  39. if __name__ == '__main__':
  40. import sys
  41. from werkzeug.serving import run_simple
  42. run_simple('localhost', 8000, application, use_reloader=True, use_debugger=True, use_evalex=True)