Home > other >  Please help me to figure out where is the actual bugs, I did correctly but didn't get to work a
Please help me to figure out where is the actual bugs, I did correctly but didn't get to work a

Time:01-18

{% extends 'main.html' %}
{% load static %}
{% block content %}
{% if page == "register" %}
<h1>Hello This is register Page!!!</h1>
<form method="POST" action="{% url 'register' %}">
  {% csrf_token %} {{form.as_p}}
  <input type="submit" value="Register" />
</form>
<p>Aready have an account <a href="{% url 'login' %}"> Login </a></p>
{% else %}
<div >
  <div >
    <div >
      <a href="/">
        <img src="{% static 'images/icon.svg' %}" alt="icon" />
      </a>
      <h3>Account Login</h3>
      <p>Hello Developer, Welcome Back!</p>
    </div>

    <form action="{% url 'login' %}" method="POST" >
      {% csrf_token %}
      <!-- Input:Email -->
      <div >
        <label for="formInput#text">Username: </label>
        <input
          
          id="formInput#text"
          type="text"
          name="username"
          placeholder="Enter your username..."
        />
      </div>

      <!-- Input:Password -->
      <div >
        <label for="formInput#password">Password: </label>
        <input
          
          id="formInput#passowrd"
          type="password"
          name="password"
          placeholder="••••••••"
        />
      </div>
      <div >
        <input  type="submit" value="Log In" />
        <a href="forgetpassword.html">Forget Password?</a>
      </div>
    </form>
    <div >
      <p>Don’t have an Account?</p>
      <a href="{% url 'register' %}">Sign Up</a>
    </div>
  </div>
</div>
{% endif %}
{% endblock content %}

Here is my main.html:

<!DOCTYPE html>
{% load static %}
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <!-- Favicon -->
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
    <!-- Icon - IconMonster -->
    <link
      rel="stylesheet"
      href="https://cdn.iconmonstr.com/1.3.0/css/iconmonstr-iconic-font.min.css"
    />
    <!-- Mumble UI -->
    <link rel="stylesheet" href="{% static 'uikit/styles/uikit.css' %}" />
    <!-- Dev Search UI -->
    <link rel="stylesheet" href="{% static 'styles/main.css' %}" />
    <link rel="stylesheet" href="{% static 'uikit/styles/app.css' %}" />

    <title>DevSearch - Connect with Developers!</title>
  </head>
  <body>
    {% include 'navbar.html' %} 
    {% if messages %}
    <ul >
        {% for message in messages %}
        <li{% if message.tags %} {% endif %}>{{ message }}</li>
        {% endfor %}
    </ul>
    {% endif %}
    {% block content %} 
    {% endblock content %}
  </body>
</html>

and here is the error I have been taking Udemy course "Learn to build awesome websites with Python & Django!" by Dennis Ivy and I have reached almost middle of the course but when I reached here I was badly stuck with these errors. Highly appreciated if some grate people spare some of your time and help me to get rid of this errors.

TemplateSyntaxError at /login/
Invalid block tag on line 38: 'else', expected 'endblock'. Did you forget to register or load this tag?
Request Method: GET
Request URL:    http://127.0.0.1:8000/login/
Django Version: 4.0.1
Exception Type: TemplateSyntaxError
Exception Value:    
Invalid block tag on line 38: 'else', expected 'endblock'. Did you forget to register or load this tag?
Exception Location: D:\Python\Django\devsearch\djenv\lib\site-packages\django\template\base.py, line 552, in invalid_block_tag
Python Executable:  D:\Python\Django\devsearch\djenv\Scripts\python.exe
Python Version: 3.10.0

if I put {% load static %} above else block as below, it does work but I have to use inside if statement also, so when I do it as above, it gives error.

{% extends 'main.html' %}{% block content %}{% if page == 'register' %}
<h1>Hello This is register Page!!!</h1>
<form method="POST" action="{% url 'register' %}">
  {% csrf_token %} {{form.as_p}}
  <input type="submit" value="Register" />
</form>

{% load static %} {% else %}
<div >
  <div >
    <div >
      <a href="/">
        <img src="{% static 'images/icon.svg' %}" alt="icon" />
      </a>
      <h3>Account Login</h3>
      <p>Hello Developer, Welcome Back!</p>
    </div>

    <form action="{% url 'login' %}" method="POST" >
      {% csrf_token %}
      <!-- Input:Email -->
      <div >
        <label for="formInput#text">Username: </label>
        <input
          
          id="formInput#text"
          type="text"
          name="username"
          placeholder="Enter your username..."
        />
      </div>

      <!-- Input:Password -->
      <div >
        <label for="formInput#password">Password: </label>
        <input
          
          id="formInput#passowrd"
          type="password"
          name="password"
          placeholder="••••••••"
        />
      </div>
      <div >
        <input  type="submit" value="Log In" />
        <a href="forgetpassword.html">Forget Password?</a>
      </div>
    </form>
    <div >
      <p>Don’t have an Account?</p>
      <a href="{% url 'register' %}">Sign Up</a>
    </div>
  </div>
</div>
{% endif %} {% endblock content %}

Here is my nave-bar.html:

{% load static %}

<!-- Header Section -->

<header >
  <div >
    <a href="{% url 'profiles' %}" >
      <img src="{% static 'images/logo.svg' %}" alt="DevSearch Logo" />
    </a>
    <nav >
      <input type="checkbox" id="responsive-menu" />
      <label for="responsive-menu" >
        <span>Menu</span>
        <div ></div>
      </label>
      <ul >
        <li >
          <a href="{% url 'profiles' %}">Developers</a>
        </li>
        <li >
          <a href="{% url 'projects' %}">Projects</a>
        </li>
        <li ><a href="inbox.html">Inbox</a></li>
        {% if request.user.is_authenticated %}
        <li >
          <a href="{% url 'create-project' %}">Add Projects</a>
        </li>
        <li >
          <a href="{% url 'logout' %}" >Log Out</a>
        </li>
        {% else %}
        <li >
          <a href="{% url 'login' %}" >Login/Sign Up</a>
        </li>
        {% endif %}
      </ul>
    </nav>
  </div>
</header>

CodePudding user response:

Try defining the if statement within the block content ie give tab spacing as if you are defining a function

CodePudding user response:

The main problem I noticed is the {%load static%}. If I remove static functionality from the code, it is rendering pages as expected with if else conditions, but sadly it doesn't give affect to my few icons.

Thank you guys, it is my first time on stackoverflow and I really appreciate you guys time, commitment for help, and helpfulness thoughts.

  •  Tags:  
  • Related