i am new to django and i want to make a simple form, according to the doc i can make a form using forms module from django
from django import forms class CronForm(forms.Form): name = forms.CharField(max_length=100) email = forms.EmailField(required=False, label='Your e-mail address') message = forms.CharField(widget=forms.Textarea) def clean_message(self): message = self.cleaned_data['message'] num_words = len(message.split()) if num_words < 4: raise forms.ValidationError("Not enough words!") return message
what i want to know is how to create a dropdown list of days in month i.e from 1 to 31?
some have done it using javascript in their form template, can this be done in django?
You're looking for a ChoiceField
which renders as a select
html element by default. https://docs.djangoproject.com/en/dev/ref/forms/fields/#choicefield
class CronForm(forms.Form): days = forms.ChoiceField(choices=[(x, x) for x in range(1, 32)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With