tags:

views:

92

answers:

4

hi, I developped a django website on my local machine and now is the time to upload it on a server. I would like that during the time i work on it, only logged in users can see it. I thought about a

{% if is_logged_in %}
{% else %}
{% endif %}

structure in my base.py template but not all my views return a Context so it doesn't always work.

Is there any simple way without having to change much of code to hide every pages?

+4  A: 

Use django.contrib.auth.decorators.login_required. It is a decorator, that will prevent users from viewing anything, if they are not logged in. Or you can find middleware for this: http://djangosnippets.org/snippets/1179/.

Middleware will be better, becuase it is unobtrusive and you can remove it later.

gruszczy
+4  A: 

There are 2 reasonable solutions for this.

  1. Using a middleware to demand authentication (if needed I can put an example online, but the code should be trivial)
  2. Using authentication in your webservers. That way you can simply add a couple of IP addresses and/or users to have access. These days it's pretty easy to link your http authentication to Django aswell so with both mod_wsgi and mod_python you can let Apache authenticate it's users via Django.
WoLpH
A: 

Another reasonable way to do this would be to client certificates. That way you can also test the parts that don't require you to be logged in

gnibbler
A: 

or protect the whole directory on the server with .htaccess and this also prevents google finding the site in development.