yeah been a while since I personally used Django. I think it was beginning of 1.11ish I believe. Just trying to see if there's something comparable to the Masonite middleware example above where its:
--> execute a "before" middleware (cleaning the request, setting some variables on some classes, redirecting for auth, etc)
--> execute the controller method (django view)
--> execute an "after" middleware (setting response headers, setting status code, converting controller method response (i.e dictionary to json converting) etc)
--> execute a "before" middleware (cleaning the request, setting some variables on some classes, redirecting for auth, etc)
You mean like this?
defglobal_auth_middleware(get_response):defmiddleware(request):ifnotrequest.user.is_authenticated:returnredirect('/login/')# before logic here
request.some_property=Property.objects.get(request['HTTP_X_PROPERTY_ID'])returnget_response(request)returnmiddleware
--> execute an "after" middleware (setting response headers, setting status code, converting controller method response (i.e dictionary to json converting) etc)
Could be something like this.
defglobal_auth_middleware(get_response):defmiddleware(request):ifnotrequest.user.is_authenticated:returnredirect('/login/')# 'after' logic here
response=get_response(request)response['X-Custom-Header']='somevalue'returnresponsereturnmiddleware
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
yeah been a while since I personally used Django. I think it was beginning of 1.11ish I believe. Just trying to see if there's something comparable to the Masonite middleware example above where its:
--> execute a "before" middleware (cleaning the request, setting some variables on some classes, redirecting for auth, etc)
--> execute the controller method (django view)
--> execute an "after" middleware (setting response headers, setting status code, converting controller method response (i.e dictionary to json converting) etc)
Thanks though!
Hmm, maybe I'm misunderstanding you, but:
--> execute a "before" middleware (cleaning the request, setting some variables on some classes, redirecting for auth, etc)
You mean like this?
Could be something like this.