简体   繁体   中英

Where am I going wrong

So I am very new to Django and I am confused where am I going wrong. I am trying to create a simple calculator to calculate profit estimates. Here is what it shows in my HTML so far. Kind of confused where am I going wrong. Any help appreciated.

在此处输入图像描述

This the HTML file code

<!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

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

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

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.

You should change

from .forms import Calc

to

from .forms import Calculator

and in the something function

form = Calculator()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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