Django.fun

form.html in Django CreateView

Below is my code.

class ArticleCreateView(OwnerCreateView):
    model = Article
    fields = ['title', 'text']
class OwnerCreateView(LoginRequiredMixin, CreateView):
    """
    Sub-class of the CreateView to automatically pass the Request to the Form
    and add the owner to the saved object.
    """

    # Saves the form instance, sets the current object for the view, and redirects to get_success_url().
    def form_valid(self, form):
        print('form_valid called')
        object = form.save(commit=False)
        object.owner = self.request.user
        object.save()
        return super(OwnerCreateView, self).form_valid(form)

In my /home/JongRok/dj4e-samples/myarts/templates/myarts I have acticle_form.html

{% extends "base_bootstrap.html" %}
{% load crispy_forms_tags %}
{% block content %}
<p>
  <form action="" method="post">
    {% csrf_token %}
    {{ form|crispy }}
    <input type="submit" value="Submit">
    <input type="submit" value="Cancel" onclick="window.location.href='{% url 'myarts:all' %}';return false;">
  </form>
</p>
{% endblock %}

I don't understand How Django CreateView find form. I don't put form in ArticleCreateView and I don't have form.py.

How Django CreateView find it self has a model form??

Answers: 0