[Answered ]-Passing variable from urls.py to html

1👍

At first the messages is only acting as a keyword argument since you’re passing it through path() function, they are not like messages framework, they are just only kwargs to show in the templates unlike messages which appear only one time and disappear when the page is refreshed.

So, overall you should use the way it is working, passing it as the kwargs is not the recommended way since they’d appear all the time.

You can confirm this by printing its value in the template as:

<!-- Django's built-in message template part -->

{% for message in messages %}

    {% if message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %}

        <h6 id="message-timer" class="alert alert-success text-center"> <i class="fa fa-sign-out" aria-hidden="true"></i> &nbsp; {{ message }} </h6>

    {% endif %}

    {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}

        <h6 id="message-timer" class="alert alert-danger text-center"> <i class="fa fa-exclamation" aria-hidden="true"></i> &nbsp; {{ message }} </h6>

    {% endif %}

    {% if message.level == DEFAULT_MESSAGE_LEVELS.INFO %}

    <h6 id="message-timer" class="alert alert-info text-center"> <i class="fa fa-check-circle" aria-hidden="true"></i> &nbsp; {{ message }} </h6>

    {% endif %}

{% endfor %}

<h1>Your message: {{messages}}</h1>  {% comment %} It is acting as a kwarg and would appear all the time and can't be used as a message. {% endcomment %}

Leave a comment