J'ai vu ça poste mais cela ne m'a pas aidé
Dans la fenêtre modale, le formulaire n'est pas affiché.
Voir :
class CreateOrder(FormView):
template_name = 'toner/add_order.html'
form_class = OrderForm
success_url = '/toner/'
def form_valid(self, form):
form.save()
return super(CreateOrder, self).form_valid(form)
add_order.html :
<div id="order" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<div class="container txt-box">
<form action="{% url 'add_order' %}" role="form" method="post">
{% csrf_token %}
{{ form.media }}
{{ form.address }}
{{ form.room }}
{{ form.count }}
<button class="btn btn-success" type="submit">
Done
</button>
</form>
</div>
</div>
</div>
</div>
page_principale.html :
{% extends 'toner/base.html' %}
{% block main_page %}
....
<div>
<button class="btn btn-primary" data-toggle="modal" data-
target="#order">
Order
</button>
{% include "toner/add_order.html" %}
</div>
{% endblock %}
urls :
url(r'add_order/$', CreateOrder.as_view(), name='add_order'),
Si je vais directement à l'url (/add_order), cela fonctionne. Je peux voir le formulaire. Mais à partir de main_page.html la fenêtre modale est vide. Peut-être quelqu'un a-t-il déjà résolu une telle tâche ?
UPDATE
from django.views.generic import ListView, FormView
from .models import Printer, Order
from .forms import OrderForm
class MainPageView(ListView):
template_name = 'toner/main_page.html'
model = Printer
def get_context_data(self, **kwargs):
context = super(MainPageView, self).get_context_data(**kwargs)
context['printer'] = Printer.objects.all()
context['order'] = Order.objects.all()
return context
class CreateOrder(FormView):
template_name = 'toner/add_order.html'
form_class = OrderForm
success_url = '/toner/'
def form_valid(self, form):
form.save()
return super(CreateOrder, self).form_valid(form)