Page display error - Django

Asked

Viewed 119 times

2

At Django I’m developing a Library project! (I’m Beginner at Django, I’ve never worked with web development)

Summarizing I have in the file models.py a model Library and a model Book, in the model Book there is a Library Foreignkey.

The entire project is on Github, there can be viewed models.py, Forms.py and views.py

Marked red in the image, this error generated on my page.

Erro no HTML

Code of My template:

{% extends 'base.html' %}
{% load staticfiles %}

{% block title %}Chameleon | Cadastro de Livro{% endblock %}

{% block Estilo %}
<link href="{% static 'css/cadastros.css' %}" rel="stylesheet">
{% endblock %}

{% block Corpo %}       
<div class="container">

  <form class="form-signin" role="form" action="." method="post"> {% csrf_token %}
    <h2 class="form-signin-heading">Cadastro</h2>

    <input type="text" class="form-control" id="codigo" name= "codigo" placeholder="Codigo" required autofocus>
    <input type="text" class="form-control" id="titulo" name= "titulo" placeholder="Titulo" required>
    <input type="text" class="form-control" id="autor" name= "autor" placeholder="Autor" required>
    <input type="text" class="form-control" id="editora" name= "editora" placeholder="Editora" required>
    <input type="text" class="form-control" id="genero" name= "genero" placeholder="Genero" required>
    <input type="text" class="form-control" id="publicacao" name= "publicacao" placeholder="Ano: 0000" required>


    <textarea id="sinopse" name="sinopse" placeholder="Sinopse" rows = 10 cols = 63 required></textarea><hr>

    <select id="biblioteca" name="biblioteca">
        <option value="" selected="selected"> ------------- </option>
        <option value="{{ form.biblioteca }}" selected="selected"></option>
    </select><hr>

    <br><p><button class="btn btn-lg btn-primary btn-block" type="submit">Salvar</button></p>
  </form>

</div>
{% endblock %}

{% block JScript %}
{% endblock %}

When I display the page source code the tag part <select> this way:

<!-- Inicio Select --> 
<select id="id_biblioteca" name="biblioteca">

    <option value="" selected="selected"> ------------- </option>
    <option value= "<select id="id_biblioteca" name="biblioteca"><option value="" selected="selected">---------</option><option value="1">Chameleon</option></select>" selected="selected"></option>

</select><hr>
<!-- Fim Select --> 

1 answer

2


Your Library Foreignkey in the Book means a book can be/exist in more than one library?

Trade all your <select> by just {{ form.biblioteca }} that then Django will print:

<select id="id_biblioteca" name="biblioteca">
    <option value="" selected="selected">---------</option>
    <option value="1">Chameleon</option>
</select>
  • 3

    It means that a Library can have several books!

Browser other questions tagged

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