views.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.http import StreamingHttpResponse, JsonResponse
  2. from django.conf import settings
  3. from wsgiref.util import FileWrapper
  4. from rest_framework.exceptions import APIException
  5. import mimetypes, os
  6. def robots(request):
  7. path = settings.BASE_DIR + request.path_info
  8. content_type, encoding = mimetypes.guess_type(path)
  9. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  10. resp['Cache-Control'] = "max-age=864000000000"
  11. return resp
  12. def favicon(request):
  13. path = str(settings.BASE_DIR) + '/static/img/logo.png'
  14. content_type, encoding = mimetypes.guess_type(path)
  15. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  16. resp['Cache-Control'] = "max-age=864000000000"
  17. return resp
  18. def css(request):
  19. path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info
  20. content_type, encoding = mimetypes.guess_type(path)
  21. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  22. resp['Cache-Control'] = "max-age=864000000000"
  23. return resp
  24. def js(request):
  25. path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info
  26. content_type, encoding = mimetypes.guess_type(path)
  27. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  28. resp['Cache-Control'] = "max-age=864000000000"
  29. return resp
  30. def statics(request):
  31. path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info
  32. content_type, encoding = mimetypes.guess_type(path)
  33. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  34. resp['Cache-Control'] = "max-age=864000000000"
  35. return resp
  36. def fonts(request):
  37. path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info
  38. content_type, encoding = mimetypes.guess_type(path)
  39. resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)
  40. resp['Cache-Control'] = "max-age=864000000000"
  41. return resp
  42. def myip(request):
  43. import socket
  44. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  45. s.connect(('8.8.8.8', 80))
  46. print(s.getsockname()[0])
  47. ip = s.getsockname()[0]
  48. s.close()
  49. return JsonResponse({"ip": ip})