Setting environmental variable

I have requirement to display Website Launch page (page to launch the website by CEO) for one time and all subsequent visits will route to Login page. What is the right approach to achieve this?

  1. Environment variables
  2. Database flag

Thanks

Please define exactly what you mean by:

Is that one viewing _only? Once per browser? Once per authenticated user? Once per IP address?

One viewing only, before the site goes public for all users.

Currently I am doing it using a database flag and routing appropriately using two views, but I am not sure if it is the right approach. The code is like this:


def launch_view(request, *args, **kwargs):
    base_settings = BaseSettings.objects.get(pk=1)
    if request.method == 'POST':
        base_settings.portal_launched = True
        base_settings.save()
    if base_settings.portal_launched:
        return redirect(reverse('home'))
    return render(request, 'launch.html', context={'base_settings': base_settings})
@login_required
def home_view (request, *args, **kwargs):
    return render(request, 'home-view.html', context={})

and the url.py like this

path('', launch_view, name='launch'),
path('home/', home_view, name='home'), # /home /index /root

Thanks

First, the description of your requirements doesn’t match your code.

As long as whatever form isn’t posted on your launch_view, that launch.html will be visible on the site. It could be viewed any number of times.

Likewise, there’s no security or protection on that page. Anyone seeing that page can post to that url causing the status to be changed.

If you’re looking for advice here, we’re going to need a better definition of the requirements. Repeating the statement “one viewing only” does not define what the real requirement is. What is the actual objective for what you’re looking to accomplish here? What are you trying to achieve by doing this?