Re: Custom Middleware TypeError exception
On Dec 5, 11:20 am, Chris Smith <[EMAIL PROTECTED]> wrote: > Found an oddity - possibly in my code. Can't seem to work around it. > > Code in question (current multi-tenant middleware implementation): > > middleware.py .. > > from projectname.models import Tenant, HostEntry > from django.http import HttpResponseNotFound > from django.core.exceptions import ObjectDoesNotExist > > class MultiTenantMiddleware(object): > """Multi tenant middleware""" > def process_request(self, request): > http_host = request.META['HTTP_HOST'] > try: > host_entry = HostEntry.objects.get(host=http_host) > except ObjectDoesNotExist: > return HttpResponseNotFound("Host not found") > request.tenant = host_entry.tenant > return None > > - > > Exception details > > Environment: > > Request Method: GET > Request URL:http://localhost:8000/ > Django Version: 1.0.2 final > Python Version: 2.6.0 > Installed Applications: > ['django.contrib.sessions', 'productname'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'vhdesk.middleware.MultiTenantMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in > get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > > Exception Type: TypeError at / > Exception Value: test() takes exactly 1 argument (2 given) > > - > > Only occurs after i "return None". If the host entry is not found it > works correctly. In that case, it's not this Middleware that's your culprit. Look in the view function for your base URL (/). Perhaps your view function is called "test" but is not defined properly? For example, you might have a non-optional second parameter defined for the test function. -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom Middleware TypeError exception
On Dec 5, 4:20 pm, Chris Smith <[EMAIL PROTECTED]> wrote: > Any ideas? Is it something silly I've done? Actually, please ignore this. The exception was firing in user code due to me forgetting to handle a capture group in a URL regex. Back to the coffee machine... Cheers, Chris. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Custom Middleware TypeError exception
Found an oddity - possibly in my code. Can't seem to work around it. Code in question (current multi-tenant middleware implementation): middleware.py .. from projectname.models import Tenant, HostEntry from django.http import HttpResponseNotFound from django.core.exceptions import ObjectDoesNotExist class MultiTenantMiddleware(object): """Multi tenant middleware""" def process_request(self, request): http_host = request.META['HTTP_HOST'] try: host_entry = HostEntry.objects.get(host=http_host) except ObjectDoesNotExist: return HttpResponseNotFound("Host not found") request.tenant = host_entry.tenant return None - Exception details Environment: Request Method: GET Request URL: http://localhost:8000/ Django Version: 1.0.2 final Python Version: 2.6.0 Installed Applications: ['django.contrib.sessions', 'productname'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'vhdesk.middleware.MultiTenantMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) Exception Type: TypeError at / Exception Value: test() takes exactly 1 argument (2 given) - Only occurs after i "return None". If the host entry is not found it works correctly. Any ideas? Is it something silly I've done? Cheers, Chris. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---