未在 html 中显示表格

Not showing the Form in html

这是我的模型

class showroom(models.Model):
 serialno=models.IntegerField(db_index=True,primary_key=True)
 carname=models.CharField(max_length=50)
 carmodel=models.CharField(max_length=50)
 price=models.IntegerField()
 rating=models.IntegerField(validators=[MinValueValidator(1),MaxValueValidator(5)])

这是我的forms.py

class RegisterForm(ModelForm):
 class Meta:
    model = showroom
    fields =("__all__")

views.py

class carform(CreateView):
 model = showroom
 form_class=RegisterForm
 template_name = "carbrand/carregister.html"
 context_object_name='registerform'

html 页

{% block content %}
    {{registerform}}
{% endblock content %}

只是显示空白屏幕。我已经导入了所有必要的 类 和视图。这对你来说太长了,所以我删除了 it.can 如果我的 view/form.

有任何问题,请告诉我

表单名称未由 context_object_name 确定。事实上,在 CreateView 中,context_object_name 不会改变任何东西,因为没有传递任何对象。

A FormView(及其后代),始终将构造为 form 的形式传递给上下文。因此,您应该使用以下方式呈现:

{% block content %}
  <form method="post" action="{% url '<em>some-view-name</em>' %}">
    {% csrf_token %}
    {{ <strong>form</strong> }}
    <button type="submit">submit</button>
  </form>
{% endblock content %}