Wow, was that ever easy. Thanks for your help!
Kurt
For future googlers:
settings.py:
MIDDLEWARE_CLASSES = (
...
'redirector.ConstructionFilterMiddleware',
...
)
redirector/__init__.py:
from django.shortcuts import render_to_response
from django.conf import settings
class ConstructionFilterMiddleware(object):
"""
This middleware redirects all requests from clients that are
not in INTERNAL_IPS to the construction.html page
"""
def process_request(self, request):
remote_addr = request.META['REMOTE_ADDR']
is_internal = remote_addr in settings.INTERNAL_IPS
if not is_internal:
return render_to_response( 'construction.html' )
On 2009-10-04, at 1:19 PM, Kristaps Kūlis wrote:
> You should and must do such things at middleware (as god intended).
>
> example: http://www.djangosnippets.org/snippets/845/
> just return custom HttpResponse, not HttpResponseForbiden
>
>
> Kristaps Kūlis
> On Sun, Oct 4, 2009 at 8:41 PM, Kurt <kneuf...@burgundywall.com>
> wrote:
>
>>
>>
>> I think I must be doing something fundamentally wrong since this
>> seems
>> like an easy problem...
>>
>> I'm building a site, I want all ips not in INTERNAL_IPS to get an
>> "under construction" page and my internal ips to get the real site.
>> What I'm trying to do is call the application urlconf via the resolve
>> function.
>>
>> The redirect to the construction page works fine.
>>
>> The resolve seems to work since the /admin/ pages work but
>> django_authopenid do not, I get strange errors like "Reverse for
>> 'user_sendpw' with arguments '()' and keyword arguments '{}' not
>> found."
>>
>> If I change settings.py:ROOT_URLCONF to be "myapp.urls" then
>> authopenid works.
>>
>> settings.py:
>> ROOT_URLCONF = 'redirector.urls'
>>
>> redirector/urls.py:
>> urlpatterns = patterns('',
>> (r'^', 'redirector.views.redirect' ),
>> )
>>
>> redirector/views.py:
>> def redirect(request, *args, **kwargs):
>> remote_addr = request.META['REMOTE_ADDR']
>> is_internal = remote_addr in settings.INTERNAL_IPS
>>
>> if not is_internal:
>> return render_to_response( 'construction.html' )
>>
>> uri = request.META.get('REQUEST_URI', '/' )
>>
>> # if we're an internal ip address then find the application
>> urlconf
>> app = settings.SETTINGS_MODULE.split( "." )[0]
>> app_urls = app + ".urls"
>>
>> # FANCY BIT IS RIGHT HERE
>> view, args, kwargs = resolve( urlparse(uri)[2], app_urls )
>>
>> return view(request, *args, **kwargs)
>>
>>
--~--~---------~--~----~------------~-------~--~----~
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
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---