0

I have created a form to take input from an HTML page like given bellow:

form.py 

  class In_Form(forms.Form):
        Input_peptide  = forms.CharField(label='Start Year ', max_length=100)
        sites_to_be_muted = forms.CharField(label='End Year', max_length=100)
        Amino_acide = forms.CharField(label='End Year ', max_length=100,)

Update:

Is there any method through which I can set a default value for html form. I have tried "initial" but its not working in my case. This form.py is not related to model its just a form getting user input and processing that data through a script and returning result to a view and rendering output as "result.html" page: please help

jax
  • 3,927
  • 7
  • 41
  • 70
  • `initial` param should work as it's standard feature of form fields ([Django Docs](https://docs.djangoproject.com/en/1.11/ref/forms/fields/#initial)). Alternatively you can set field initial value in form `__init__` method.: self.fields['Amino_acide'].initial = 'some value', (keep in mind to call super previously). – temasso Oct 07 '17 at 13:50
  • thanks for your comment, I would be very helpful if you explain it as a separate answer with example. I am not getting what exactly you want to say. thanks – jax Oct 07 '17 at 13:56
  • Please look at answer to question [Django custom form field initial data](https://stackoverflow.com/questions/7945898/django-custom-form-field-initial-data/7945960#7945960). It contains example code. – temasso Oct 07 '17 at 14:02

1 Answers1

1

Use the initial argument when you create a Form instance.

form = In_Form(initial={'Input_peptide': '2017'})

Reference

aprasanth
  • 1,079
  • 7
  • 20