Jump to content

Please help me fix my website

Go to solution Solved by C2dan88,

The user is being logged out is because In your header for the Account sub-menu you have malformed html for handling the logout button. You fail to close the form in layout.html

        ...
        {% if user.is_authenticated %}
        <form method="POST" action="{%url 'logout'%}" class="accounts">
            {% csrf_token %}
            <lt><a href="{%url 'profile'%}">My Profile</a></lt>
            <li><button type="submit" class="accounts logout" >Logout</button></li>

        {% else %}
            <li><a href="{% url 'login' %}" class="accounts">Login</a></li>
            <li><a href="{% url 'signup' %}" class="accounts">Sign Up</a></li>
        {% endif %}
        ....

You need a closing </form> tag before the {% else %}

 

Without it the form action for updating the profile picture will be ignored by the browser. This is why the user is logged out when updating the picture.

 

But typically you logout users from a link not from a form. 

 

 

I am a self-learning web developer and I managed to make a basic company portfolio website, and I was pretty happy with it. Unfortunately, I decided to try and add accounts and profile pictures to the mix. The profile pictures can be updated from the admin console, but not from the actual pfp update form. Instead, it just logs you out. I have run out of YT tutorials at this point. Heres the gith repo- HotLoli/Help-me

 

The admin username is admin
password- travel1fun

 

Link to comment
https://linustechtips.com/topic/1612333-please-help-me-fix-my-website/
Share on other sites

Link to post
Share on other sites

The user is being logged out is because In your header for the Account sub-menu you have malformed html for handling the logout button. You fail to close the form in layout.html

        ...
        {% if user.is_authenticated %}
        <form method="POST" action="{%url 'logout'%}" class="accounts">
            {% csrf_token %}
            <lt><a href="{%url 'profile'%}">My Profile</a></lt>
            <li><button type="submit" class="accounts logout" >Logout</button></li>

        {% else %}
            <li><a href="{% url 'login' %}" class="accounts">Login</a></li>
            <li><a href="{% url 'signup' %}" class="accounts">Sign Up</a></li>
        {% endif %}
        ....

You need a closing </form> tag before the {% else %}

 

Without it the form action for updating the profile picture will be ignored by the browser. This is why the user is logged out when updating the picture.

 

But typically you logout users from a link not from a form. 

 

Link to post
Share on other sites

14 hours ago, C2dan88 said:

The user is being logged out is because In your header for the Account sub-menu you have malformed html for handling the logout button. You fail to close the form in layout.html

        ...
        {% if user.is_authenticated %}
        <form method="POST" action="{%url 'logout'%}" class="accounts">
            {% csrf_token %}
            <lt><a href="{%url 'profile'%}">My Profile</a></lt>
            <li><button type="submit" class="accounts logout" >Logout</button></li>

        {% else %}
            <li><a href="{% url 'login' %}" class="accounts">Login</a></li>
            <li><a href="{% url 'signup' %}" class="accounts">Sign Up</a></li>
        {% endif %}
        ....

You need a closing </form> tag before the {% else %}

 

Without it the form action for updating the profile picture will be ignored by the browser. This is why the user is logged out when updating the picture.

 

But typically you logout users from a link not from a form. 

 

Thank you so much. I was trying to troubleshoot this for more than a week now. You really saved me. Also, the reason I am using a form and not a link is because django only wanted the method to be post. If you can tell me how to put that in a link, that would be extra helpful. 

 

Link to post
Share on other sites

  • 2 weeks later...
On 5/19/2025 at 7:24 AM, GT710 Connoisseur said:

Thank you so much. I was trying to troubleshoot this for more than a week now. You really saved me.

Just a tip, there is extensions for VSCode to detect missing tags, and other irritants

 

Microsoft also provides github copilot for free thatd likely find the issue rather quickly

Link to post
Share on other sites

On 5/31/2025 at 7:34 PM, W1ll1aming said:

Just a tip, there is extensions for VSCode to detect missing tags, and other irritants

 

Microsoft also provides github copilot for free thatd likely find the issue rather quickly

Thanks for the suggestion, but I was trying real hard with copilot as well, but it also got really confused. Now, I just use react and ShadCN, so, it really isnt a concern right now.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×