Question: Lets say I have

.decs

```
def unwelcome_user(unwelcome_roles=[]):
        def decorator(view_func):
            def wrapper_func(request, *args, **kwargs):
                if request.user.is_authenticated:
                    for group in request.user.groups.all():
                        if group.name in unwelcome_roles:
                            return redirect('main:unwelcome-user-type', 
                                             user_type=group.name)
                        else:
                            return view_func(request, *args, **kwargs)
                else:
                    return view_func(request, *args, **kwargs)
            return wrapper_func
        return decorator

```

.urls

```
urlpatterns = [
    path('error-unwelcome/<str:user_type>', views.unwelcome_user, name='success')
]

```

.views

```
@unwelcome_user(unwelcome_roles=['xyz'])
def success(request) 
    return render(request, 'success_page.html', {})

def unwelcome_user(request, user_type):
return render(request, 'errors/unwelcome_user.html', {})

```

I can access the unwelcome\_user view directly by typing something like mysite.com/error-unwelcome/xyz in the browser even without going through the subsequent process that should result in showing that page.
How do I prevent that?

Answer: 
I'm still new to Django so I couldn't try out the cookie/sessions answers given (I still have to learn sessions). In the meantime, here's what I'm using:

```
def get_referer(request):
    referer = request.META.get('HTTP_REFERER')
    if not referer:
        return None
    return referer

```

then in any view

```
def my_view(request):
    if not get_referer(request):
        raise Http404
    return render(request, 'sample.html', {})

```

Here I'm assuming that if there's no referer, then it means the person typed in the URL into the browser.
Give this a try

The process\_page will only render success.html if `your_subsequent_process()` returns a `True`, otherwise, the process.html will be rendered.

```
def proces_page(request):
    """Your Process View"""

    if your_subsequent_process():
        return render(request, 'success.html', {})

    return render(request, 'proces.html', {})

```