How I can either deny a login or registration a user based on current session
<p>How can I deny or redirect an active user to the logged-in screen?</p>

<p>I want, user only can access pages when current session allows the access. </p>

<p>Is this can be done directly in the HTML code or only in views ?</p>

<p>If I understand you correctly, you mean that the user shouldn't see the login and signup links (maybe in the topbar). This can be done in the template as:</p>

<pre><code>{% if user.is_authenticated %}
&lt;!-- show logout link/button --&gt;
{% else %}
&lt;!-- show login and signup links/buttons --&gt;
{% endif %}
</code></pre>

<p>Also you should additionally take care of the login view in your python code for consistency (maybe security too?). I think you can do this (not tested):</p>

<pre><code>def login(request):
    # check if it's a GET/POST method
    if request.user.is_authenticated():
      return redirect(reverse('your_homepage_for_example'))
    # do login
</code></pre>

python html django redirect views