| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | from django.http import StreamingHttpResponse, JsonResponsefrom django.conf import settingsfrom wsgiref.util import FileWrapperfrom rest_framework.exceptions import APIExceptionimport mimetypes, osdef robots(request):    path = settings.BASE_DIR + request.path_info    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef favicon(request):    path = str(settings.BASE_DIR) + '/static/img/logo.png'    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef css(request):    path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef js(request):    path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef statics(request):    path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef fonts(request):    path = str(settings.BASE_DIR) + '/templates/dist/spa' + request.path_info    content_type, encoding = mimetypes.guess_type(path)    resp = StreamingHttpResponse(FileWrapper(open(path, 'rb')), content_type=content_type)    resp['Cache-Control'] = "max-age=864000000000"    return respdef myip(request):    import socket    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)    s.connect(('8.8.8.8', 80))    print(s.getsockname()[0])    ip = s.getsockname()[0]    s.close()    return JsonResponse({"ip": ip})
 |