user2086641
user2086641

Reputation: 4371

how to create check box and display it in templates

forms.py is

class ShowlivereportForm(forms.Form):
    livereport = forms.BooleanField()

How to create django check box

I dont't know how to create a template for showing the check box,can any one give me with an example

Upvotes: 0

Views: 282

Answers (1)

MostafaR
MostafaR

Reputation: 3695

You can use django's automatic as_p function in templates, or you can write your template manually (to have more control on it's attributes).

For automatic you need this in your template:

{{ form.as_p }}

For manual you should use something like this:

<input type="checkbox" id="livereport" name="livereport" {% if form.livereport.value %}checked="checked"{% endif %}>
<label for="livereport">Show live report</label>

Upvotes: 1

Related Questions