How to use django forms

currently when I run my app, am promoted to enter data from the terminal which i dont want eg Enter Loan Ammount

`from .forms import BasicForm` `def signup(request):`
`    if request.method == 'POST':`
`        form = BasicForm(request.POST)`
`        if form.is_valid():`
`                # Entering the loan amount`
`            isCorrectAmount = True`
`            while isCorrectAmount:`
`                enteredLoanAmount = request.POST.get(float(input("Enter Loan amount (Min - 1,000,000): ")))`
`                if enteredLoanAmount < 1_000_000:`
`                    print("Minimum Loan amount is 1,000,000")`
`                    enteredLoanAmount = float(input("Enter Loan amount (Min - 1,000,000): "))`
`                else:`
`                    isCorrectAmount = False`
`                    `
`            # Entering the age`
`            isCorrectAge = True`
`            while isCorrectAge:`
`                enteredAge = int(input("Enter Age (18 - 50 years): "))`
`                if enteredAge < 18 or enteredAge > 50:`
`                    print("Sorry, age does not meet criteria!")`
`                    enteredAge = int(input("Enter Age (18 - 50 years):"))`
`                else:`
`                    isCorrectAge = False` `            # Entering the loan term`
`            isCorrectTerm = True`
`            while isCorrectTerm:`
`                enteredTerm = int(input("Enter Loan term (3 - 35 years): "))`
`                if enteredTerm < 3 or enteredTerm > 35:`
`                    print("Sorry, loan term does not meet criteria!")`
`                    enteredTerm = int(input("Enter Loan term (3 - 35 years):"))`
`                else:`
`                    isCorrectTerm = False`
`                    `
`            # Entering the gender`
`            enteredGender = input("Enter Gender (MALE or FEMALE): ")`

I would like to stop this and enter data using my form not the terminal and my form looks something like this

`class BasicForm(forms.Form):`
`    GENDERS = (`
`        ('M', 'Male'),`
`        ('F', 'Female')`
`    )`
`    enteredLoanAmount = forms.CharField()`
`    Enter_age = forms.CharField()`
`    Enter_loan_term = forms.CharField()`
`    gender = forms.ChoiceField(widget=forms.RadioSelect, choices=GENDERS)`
`    # We should use a validator to make sure `
`    # the user enters a valid number format`
`    ` `    def __init__(self,*args, **kwargs): `
`        super().__init__(*args,*kwargs)`
`        self.helper = FormHelper(self)`
`        self.helper.form.method='post'`
`        self.helper.add_input(Submit('Save','Submit'))`

I would like to get my data rendered to my signup page

{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<div class="card" style = "width:25rem; margin:auto;">
    <div class="card-header" style="background-color:#248cd1; color:white;">
        Create your Order
      </div>
    <div class="card-body">
        <form method="POST" action="">
            {% csrf_token %}
            {% crispy form %}
        </form>
    </div>
</div>
{% endblock %}

How can I achieve that?

input() is for taking input from the terminal only.

It’s hard to tell exactly what you want to achieve here without more details. I suggest setting up a repl.it of the project and posting a link so that all you code is available. Or, you could use any of the Django tutorials all over the web for building out an example app with a form.

@jeremy.a.gray thankyou
I mean I would like to enter data using this form instead of using the terminal
Though its a runtime thing so no database is required

Did you remove the calls to input()? I understand you want to use a form, but unless you remove those calls to input(), it won’t work.

Without all the code and specific error messages and requirements, there’s really no way to identify or diagnose the problem. You really need to post a link to a repl that’s producing the error.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.