Hide django site during development

I developed the django site on my local machine, and now is the time to upload it to the server. I would like for me to work on this during this time, only registered users can see it. I'm thinking of

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

in my base.py template, but not all of my views return context, so it does not always work.

Is there an easy way without having to change most of the code to hide all pages?

+4
source share
4 answers

There are 2 reasonable solutions for this.

  • Using middleware for authentication (if necessary, I can give an example on the Internet, but the code should be trivial)
  • Using authentication in your web servers. This way, you can simply add a couple of IP addresses and / or users for access. These days, it's pretty easy to associate your HTTP authentication with Django, so with mod_wsgi and mod_python you can let Apache authenticate it with Django.
+4
source

Use django.contrib.auth.decorators.login_required . This is a decorator that will not allow users to view anything if they are not logged in. Or you can find middleware for this: http://djangosnippets.org/snippets/1179/ .

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

+4
source

Another reasonable way to do this would be client certificates. That way, you can also check for parts that don't require you to log in.

0
source

or protect the entire directory on the server using .htaccess, and this also prevents Google from finding the site in development.

0
source

Source: https://habr.com/ru/post/1316532/


All Articles