Shift the "Login link" to the right side of the Bootstrap navbar

Currently working on a Django website and incorporating Bootstrap/CSS/HTML to enhance the design.

I've set up a navbar menu and want the login tab on the right side. However, despite my attempts, I'm not achieving the desired outcome:

The HTML script I have looks like this:

{% if user.is_authenticated %}
...
display all tabs
...

<ul class="nav navbar-nav navbar-right">

<li><a href="{% url "logout" %}"><span class="glyphicon glyphicon-log-out"></span> Logout </a></li>
{% else %}
<li><a href="{% url "login" %}"><span class="glyphicon glyphicon-log-out"></span> Login </align></a></li>
{% endif %}
</ul>

For authenticated users:

https://i.sstatic.net/qFQAw.png

For non-authenticated users:

https://i.sstatic.net/Ojvj3.png

As a beginner in HTML/CSS/Bootstrap, any suggestions on how to achieve this?

Thank you

EDIT:

Full HTML script with multiple {% user.is_authenticated %}:

<!--DOCTYPE html -->
<html>
    <head>

    {% load staticfiles %}

    <title> DatasystemsEC - Home </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
    <link rel="stylesheet" type="text/css" href="{% static 'css/Base.css' %}"/>
    </head>

    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="http://www.test.fr/"> Software </a>
            </div>

            <ul class="nav navbar-nav">
                <li><a href="{% url "home" %}"> <span class="glyphicon glyphicon-home"></span> Home </a></li>
                {% if user.is_authenticated %}
                    <li><a href="{% url "profile" %}"> Profile </a></li>
                {% endif %}
            </ul>

            <ul class="nav navbar-nav navbar-right">
                {% if user.is_authenticated %}
                    <li><a href="{% url "logout" %}"><span class="glyphicon glyphicon-log-out"></span> Logout </a></li>
                {% else %}
                    <li><a href="{% url "login" %}"><span class="glyphicon glyphicon-log-in"></span> Login </a></li>
                {% endif %}
            </ul>
        </div>
    </nav>
    {% block content %}
    {% endblock content %}
</html>

Answer №1

To make it function correctly, simply place {% endif %} from the initial {% if user.is_authenticated %} right before </ul>.

Answer №2

To incorporate positioning, you can utilize the `position` attribute and define the `left` and `right` values for your elements.

<div style="position: absolute; top: 30%; left: 20%">
<ul class="nav navbar-nav navbar-right">
    <li>item</li>
</ul>
</div>

Alternatively, you have the option to apply `style="float: right; margin: 10%;"` for a similar effect.

Answer №3

.navbar-right is the class responsible for aligning links to the right side of the page in your template. Refer to the documentation for more details. It seems that this tag is not fully displayed in the {% else %} section of your template.

Depending on your template structure, you may need to include multiple {% user.is_authenticated %} tags. Below is a solution based on the provided template snippet:

{% if user.is_authenticated %}
...
display all tabs
...
{% endif %}

<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}
<li><a href="{% url "logout" %}"><span class="glyphicon glyphicon-log-out"></span> Logout </a></li>
{% else %}
<li><a href="{% url "login" %}"><span class="glyphicon glyphicon-log-out"></span> Login </align></a></li>
{% endif %}
</ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The styling of Material UI's contained button is being overridden by MuiButtonBase-root

Currently, I am working with material-ui in a react project. In one of my components, I have incorporated a simple contained button: <Button variant='contained' color='primary'> Edit</Button> However, despite setting it as ...

Animation of CSS with an image depicting a leaf swaying gently in the breeze

This project was a personal challenge for me, and I am quite satisfied with the approach I have developed. However, I am open to exploring alternative methods if there are any. The website I am working on features a logo that includes an image of a leaf. ...

"Discrepancy found in results between Node-Fetch POST and Firefox POST requests

I have encountered a challenge while trying to replicate a successful log-in process on a website using node-fetch after being able to do so with Firefox. The login process consists of three stages: Visiting /login which returns a sessionToken from the we ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...

The SVG animation is reversing and decreasing in size from the bottom

Feeling lost, I spent a day searching without success. I have a project in full Vuejs and I thought using Svg would be easy and fun, but I can't figure out why the image resizes when playing an animation. The bottom of the svg seems to resize and get ...

Why does HTML validation matter after the webpage has finished loading?

After coming across an article recommending a workaround for a method that isn't considered strictly valid (using target="_blank") by using JavaScript to apply the rules after the page has loaded, I began contemplating if this approach is ethical. It ...

Ensure that the background div extends all the way to the bottom of the page

Is there a clever CSS technique that allows a div to extend all the way to the bottom of the screen without displaying any visible content inside? Or am I better off using JavaScript for this purpose? Thank you, Richard ...

I have been working on creating a hangman game, and although I have figured out the logic behind it, I am experiencing an issue where it is not functioning properly. After inspect

I am currently working on a basic hangman game using only HTML and JavaScript. I have the logic in place, but it doesn't seem to be functioning correctly. When I inspected the element, it showed an error saying 'undefined toUppercase.' As a ...

What is the rationale behind the preset margin on the <body> tag?

Throughout my years in development, I have primarily focused on front-end web UI development. One recurring issue that has always irked me is the constant need to reset default browser styling assumptions, which often slips my mind until it starts affectin ...

Enhanced jQuery Embed Code validation for user input using a textarea

Currently, I am developing a website that allows users to input embed codes from popular platforms such as Twitter, YouTube, Instagram, Facebook, and so on. The embed code undergoes validation checks and is saved if it meets the criteria. However, when us ...

Unable to update content within the `style` attribute when the HTML is stored in a variable

I am attempting to make changes to the style html - specifically by replacing a string, but unfortunately it is not functioning as expected. I am struggling to obtain the final updated html. Below is my attempt: var html = "<style>043BF83A8FB24A418 ...

Separating the rules for development and production modes in the webpack configuration file

I'm currently in the process of working on a front-end project using HTML. Within my project, I have integrated the Webpack module bundler and am utilizing the image-webpack-loader package for image optimization. However, I've encountered an issu ...

When hovering over the bootstrap dropdown, the main dropdown remains a clickable link

How can I create a bootstrap dropdown menu that activates on hover, while still allowing the main button to link to a different page when clicked? Below is the HTML code: <div class="body-wrap"> <div class="container"> <nav class="navbar n ...

What are the steps to play this using Internet Explorer?

I am having trouble with my player code in Internet Explorer. Can anyone provide assistance on how to make it work across all browsers? <object data="http://bitcast-b.bitgravity.com/player/6/bitgravity_player_v6_1_4.swf" id="bitgravity_player_6" ...

"I'm looking for a way to display the validation summary text in a custom alert using ASP.NET. Can anyone help with

For a recent project at school, I have been tasked with creating an ASP website. One of the features on the login form is several validators and a validation summary. Although the validation summary itself is working correctly, I am looking to extract the ...

Vue.js: Issue with applying class binding while iterating over an object

I've been working with an object data that looks like this: object = { "2020092020-08-01":{ "value":"123", "id_number":"202009" }, "2020092020-09-01":{ "value& ...

Is it possible to use D3 for DOM manipulation instead of jQuery?

After experimenting with d3 recently, I noticed some similarities with jquery. Is it feasible to substitute d3 for jquery in terms of general dom management? This isn't a comparison question per se, but I'd appreciate insights on when it might b ...

Is there a way to create a timed fadeIn and fadeOut effect for a div using HTML and CSS?

I have a single div that initially displays text, and I want it to fade out after a specific time so that another div will then fade in. However, my attempt at coding this transition is not producing the desired result: $(function() { $(".preloa ...

Using node.js to submit a form and upload an image

Seeking some assistance as a newcomer to node. I am trying to achieve a task without the use of any other frameworks like Express. Here is the scenario: I have created a form where users can upload photos to a server running on a node. The form contains t ...

Validating Age Using jQuery UI Datepicker

Creating a dating platform for users over the age of 18, I am utilizing jQuery UI datepicker. To ensure only individuals above the age of 18 can register, I need the YEAR section to display 18 years earlier (1997) instead of the current year (2016). This w ...