The hidden input field that you are referring to is the following:
<input type="hidden" name="csrfmiddlewaretoken" value="brsd4oO0qhMw2K8PyCIgSgEMqy7QFvEjTHaR6wTJmyWffJaCX5XyOMDLrGldZ3ji">
This is Django’s CSRF token, which you have correctly included in your form, and should always be an <input type="hidden"
.
You have not shown us your template code, but as long as you correctly pass the form
variable to your template, the following code should work:
<form method="post">
{% csrf_token %}
Please enter your description here: {{ form.description }}
<button>Submit</button>
{% if not form %}
You have forgot to add the <tt>form</tt> variable to your template!
{% endif %}
</form>
My problem is i set a form from a model to change the value of the field “description” of this model :
Model :
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
birth_date = models.DateField(null=True, blank=True)
profile_img = models.ForeignKey(Image,on_delete=models.CASCADE,related_name='images',null=True)
description = models.TextField()
Form :
class ChangeUserDescription(ModelForm):
class Meta:
model = Profile
fields = ['description']
widgets = {
'description': forms.Textarea()
}
labels = {
'description':'Description'
}
template :
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit">Save changes</button>
</form>
But in result of this code I obtain this :
<input type="hidden" name="csrfmiddlewaretoken" value="brsd4oO0qhMw2K8PyCIgSgEMqy7QFvEjTHaR6wTJmyWffJaCX5XyOMDLrGldZ3ji">
<button type="submit">Save changes</button>
The issue is that i get : type=”hidden” in the input whereas i want it to be visible and i do not specified in the widgets that it must be hidden.
I added the template, i tried your code but nothing change the input is still hidden and i juste see the sentences : Please enter your description here: before the submit button
Ok in fact you right i’m sorry my issue was really simple. Thanks a lot