Unexpected tokens - boostrap4

Asked

Viewed 30 times

-1

{% load bootstrap4 %}

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1,
    shrink-to-fit=no">
  <title>Learning Log</title>

  {% bootstrap_css %}
  {% bootstrap_javascript jquery='full' %}

</head>
<body>

  <nav class="navbar navbar-expand-md navbar-light bg-light mb-4 border">

    <a class="navbar-brand" href="{% url 'learning_logs:index' %}">
      Learning Log</a>

    <button class="navbar-toggler" type="button" data-toggle="collapse"
        data-target="#navbarCollapse" aria-controls="navbarCollapse"
        aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span></button>
    <div class="collapse navbar-collapse" id="navbarCollapse">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="nav-link" href="{% url 'learning_logs:topics'%}">
            Topics</a></li>
      </ul>
      <ul class="navbar-nav ml-auto">
        {% if user.is_authenticated %}
          <li class="nav-item">
            <span class="navbar-text"}">Hello, {{ user.username }}.</span>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="{% url 'users:logout' %}">Log out</a>
          </li>
        {% else %}
          <li class="nav-item">
            <a class="nav-link" href="{% url 'users:register' %}">Register</a>
          </li>
          <li class="nav-item">
           <a class="nav-link" href="{% url 'users:login' %}">Log in</a></li>
        {% endif %}
      </ul>
    </div>

  </nav>

  <main role="main" class="container">
    <div  class="pb-2 mb-2 border-bottom">
      {% block page_header %}{% endblock page_header %}
    </div>
    <div>
      {% block content %}{% endblock content %}
    </div>
  </main>

</body>

</html>

Error appears Unexpected tokens on the line <!DOCTYPE html> causing me not to be able to view the page with the bootstrap features, leaving only the "raw" part. When I remove the line {% load bootstrap4 %} the error disappears, but still the page does not load the bootstrap. I am using the book as reference Python Crash Course, and by the code that is in the book, there is nothing wrong. I am using Python3 and Django3.1 in the project.

  • You installed Django-bootstrap4 $ pip install django-bootstrap4? The dictionary bootstrap4 is defined in py Settings.?

  • exactly, missed adding bootstrap4 to Settings.py @Augustovasques

1 answer

0

Try to replace:

{% load bootstrap4 %}

for:

{% load static %}
  • 1

    missed adding bootstrap4 to Settings.py, now it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.