简体   繁体   English

我哪里错了

[英]Where am I going wrong

So I am very new to Django and I am confused where am I going wrong.所以我对 Django 很陌生,我很困惑我哪里出错了。 I am trying to create a simple calculator to calculate profit estimates.我正在尝试创建一个简单的计算器来计算利润估算。 Here is what it shows in my HTML so far.这是到目前为止在我的 HTML 中显示的内容。 Kind of confused where am I going wrong.有点困惑我哪里错了。 Any help appreciated.任何帮助表示赞赏。

在此处输入图像描述

This the HTML file code这是 HTML 文件代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>
<body>

    {% block content %}
    <form action = "something" method = "post">
        {% csrf_token %}
        {{ form }}
        <input type="submit" value=Submit>
    </form>
    {% endblock %}

</body>
</html>

This is forms.py这是 forms.py

from django import forms
from .models import Calc

class Calculator(forms.ModelForm):
    class Meta:
        model = Calc
        fields = ['gross_receivable', 'TDS', 'bank_charges', 'vendor_payable']

This is the models.py这是models.py

from django.db import models

# Create your models here.
class Calc(models.Model):
    gross_receivable = models.IntegerField()
    TDS = models.BooleanField(default=False)
    bank_charges = models.BooleanField(default=False)
    vendor_payable = models.IntegerField()

This is the views.py这是views.py

from django.shortcuts import render
from django.http import HttpResponse
from .forms import Calc

    def something(request):
        form = Calc()
        context = {'form': form}
        return render(request, "calculator1.html", context)

Your form name is Calculator but you are importing your model as form.您的表单名称是计算器,但您正在将 model 作为表单导入。

You should change你应该改变

from .forms import Calc

to

from .forms import Calculator

and in the something function在 function

form = Calculator()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM