Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a django website while development

Tags:

python

django

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 simple way without having to change much of code to hide every pages?

like image 713
Mermoz Avatar asked Feb 27 '23 14:02

Mermoz


2 Answers

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.
like image 103
Wolph Avatar answered Mar 08 '23 06:03

Wolph


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.

like image 32
gruszczy Avatar answered Mar 08 '23 07:03

gruszczy