Answer the question
In order to leave comments, you need to log in
How to add a placeholder to a model form?
How to add placeholder to inputs?
forms.py file
from django.forms import ModelForm
from .models import Question
class QuestionForm(ModelForm):
class Meta:
model = Question
fields = '__all__'
from django.db import models
class Question(models.Model):
name = models.CharField(max_length=100)
phone = models.CharField(max_length=20)
mail = models.CharField(max_length=200)
question = models.TextField()
def __str__(self):
return self.name
<form action="" method="POST">
{% csrf_token %}
<div class="row">
<div class="col-lg-6">
<p class="input-field">
{{ form.name }}
</p>
<p class="input-field">
{{ form.phone }}
</p>
<p class="input-field">
{{ form.mail }}
</p>
</div>
<div class="col-lg-6">
<p class="input-field">
{{ form.question }}
</p>
<p class="input-field">
<button type="submit" class="send-qtn">Отправить <i class="far fa-paper-plane"></i></button>
</p>
</div>
</div>
</form>
Answer the question
In order to leave comments, you need to log in
class QuestionForm(ModelForm):
class Meta:
model = Question
fields = '__all__'
widgets = {
'field_name': TextInput(attrs={'placeholder': 'some value'}),
}
fields = '__all__'
, it's bad practice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question