Ну не выскакивают окошки хоть убейся . Для теста сделал новый проект и все по инструкции . Но нифига не работает. Джангу только начал изучать , в джаве полный ноль )))
urls.py
from django.urls import path
from .views import *
urlpatterns = [
path('', BookView.as_view(), name='home'),
path('create/', BookCreateView.as_view(), name='create_book'),
]
models.py
from django.db import models
class Book(models.Model):
name = models.CharField(max_length=50, verbose_name='Книга')
author = models.CharField(max_length=100, verbose_name='Аффтор')
comment = models.TextField(verbose_name='Комментарий')
view.py
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import ListView
from .forms import CreateBookForm
from .models import Book
from bootstrap_modal_forms.generic import BSModalCreateView
class BookCreateView(BSModalCreateView):
template_name = 'book/create_book.html'
form_class = CreateBookForm
success_message = 'Success: Book was created.'
success_url = reverse_lazy('home')
class BookView(ListView):
modal = Book
template_name = 'book/home.html'
context_object_name = 'books'
def get_queryset(self):
return Book.objects.all()
forms.py
from .models import Book
from bootstrap_modal_forms.forms import BSModalModelForm
class CreateBookForm(BSModalModelForm):
class Meta:
model = Book
fields = ['name', 'author', 'comment']
base.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{% static 'book/css/bootstrap.css' %}">
</head>
<body>
{% block content %}
{% endblock %}
<script src="{% static 'book/js/bootstrap.js' %}"></script>
<!-- <script src="{% static 'assets/js/jquery.js' %}"></script>-->
<script src="{% static 'js/jquery.bootstrap.modal.forms.js' %}"></script>
<!-- You can alternatively load the minified version -->
<!-- <script src="{% static 'js/jquery.bootstrap.modal.forms.min.js' %}"></script>-->
</body>
</html>
create_book.html
<form method="post" action="">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">Create new Book</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{% for field in form %}
<div class="form-group{% if field.errors %} invalid{% endif %}">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% for error in field.errors %}
<p class="help-block">{{ error }}</p>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
home.html
{% extends 'book/base.html' %}
{% block content %}
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Название Книги</th>
<th scope="col">Аффтор</th>
<th scope="col">Кооментарий</th>
</tr>
</thead>
<tbody>
{% for item in books %}
<tr>
<th scope="row">{{ item.pk }}</th>
<td>{{ item.name }}</td>
<td>{{ item.author }}</td>
<td>{{ item.comment }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="modal fade" tabindex="-1" role="dialog" id="modal">
<div class="modal-dialog" role="document">
<div class="modal-content"></div>
</div>
</div>
<!-- Create book button -->
<button id="create-book" class="btn btn-primary" type="button" name="button">Create book</button>
<script type="text/javascript">
$(document).ready(function() {
$("#create-book").modalForm({
formURL: "{% url 'create_book' %}"
});
});
</script>
{% endblock %}
Подскажите пожалуйста что не так. На кнопку ноль реакции.
Updated 10 Jan. 2022, 9:56 by Uiclick.