contact@digitalnotebooks.co
Stay Organized, Stay Inspired. Let's Write.

Car Listing: Django Messages Part 12B

Back To All Notes
  • Notebook: Django Project: Car Listing
  • Speaker: Udemy Instructor Rathan Kumar
  • Date Created: July 20, 2024, 7:24 p.m.
  • Owner: Rosilie

1. See the DJANGO MESSAGES FRAMEWORK documentation here.

2.  We copy this block into SETTINGS.PY and modify this.

FROM:

TO:

3. Create a new file MESSAGES.HTML in the TEMPLATES\INCLUDES folder. This can be used in ANY Django with Bootrsap projects.

<!-- this is for flash messages we show on our web pages

classes here are from the bootstrap.

-->

{% if messages %}

{% for message in messages %}

<div id="message" class="container">

    <div class="alert alert-{{ message.tags }}" alert-dismissable role="alert">

        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span></button>

        <strong>

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

              Error:

            {% else %}

              {{mesaage.tags|title}}

            {% endif %}

        </strong>

        {{message}}

    </div>

</div>

{% endfor %}

{% endif %}

4. To use the message framework, go to ACCOUNTS\VIEWS.PY and update as

5. Now to display this message on our webpage like REGISTER.HTML, update the REGISTER.HTML. You have to write the line for the error message in the location you want to see it.

6. If you want your ERROR MESSAGE TO DISAPPER IN A GIVEN TIME instead of closing it, update your CARZONE\STATIC\JS\APPS.JS file as:

//time-controlled function (4 ms) for customized messages

setTimeout(function () {

    $('#message').fadeOut('slow');

}, 4000)

 

7. Run a COLLECTSTATIC for all updates made from the CARZONE\STATIC FILES AND FOLDERS.

$ python manage.py collectstatic

8. Run the server again. If the message does not disappear in 4 milliseconds, reload your REGISTER.HTML, VIEW THE PAGE SOURCE and open the APPS.JS to see if it has our SETTIMEOUT function. Reload again the webpage and test.

It should disappear after 4MS.

9. You may now continue with your USER REGISTRATION.



No PDF file attached.

Notebook
Notebook Details
Title: Django Project: Car Listing
Category: Udemy Django Course