[ピットを踏むDjango]ミドルウェアエラー:TypeError:object()はパラメータを取りませんこのように解決できます



Middleware Error



ミドルウェアを使用すると、エラーが報告されます TypeError:object()はパラメータを取りません。

元のコード :(特定のIPブラウザアクセスを禁止するための実装



from django.http import HttpResponse class BlockedIPSMiddleware(object): '''Middleware class''' EXCLUDE_IPS = ['192.168.43.28'] # List of prohibited addresses def process_view(self, request, view_func, *view_args, **view_kwargs): '''The view function will be called before the call''' user_ip = request.META['REMOTE_ADDR'] print(user_ip) if user_ip in BlockedIPSMiddleware.EXCLUDE_IPS: # When running verification, specify ip when starting the service, set ALLOWED_HOSTS = ['*'] return HttpResponse('')