开发者

Hiding a django website while development

I developed 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开发者_JAVA技巧 simple way without having to change much of code to hide every pages?


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜