23π
I wouldnβt recommend removing the label as it makes the form inaccessible. You could add a custom CSS class to the field, and in your CSS make that class invisible.
EDIT
I missed that the input was hidden so accessibility isnβt a concern.
You can render the form fields directly in your template:
<form ...>
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
{% for field in form.visible_fields %}
{{ field.label }} {{ field }}
{% endfor %}
</form>
20π
Now,(my django version is 2.1.4), you can solve in this way -> Edit forms.py file:
password = forms.CharField(label=False)
- How do I save data from a ModelForm to database in django?
- Django can't access raw_post_data
- How do you use Django-filter's '__in' lookup?
- Assign Value of Named URL to a Variable in Django Templates
7π
If you use the form.as_p
or form.as_table
method, Django shouldnβt display the labels for your hidden fields anyway, so thereβs no need to change the label in your __init__
method.
{{ form.as_table }}
If you are customizing the form template, you can use the field.is_hidden
attribute to check whether the field is hidden.
{% if field.is_hidden %}
{# Don't render label #}
{% endif %}
Alternatively, you can loop over hidden and visible fields separately, and omit the label for hidden fields.
- Django migrate and makemigrate automatic yes on prompt
- Celery beat not picking up periodic tasks
- Django Full Text SearchVectorField obsolete in PostgreSQL
- Django-rest-swagger: how to group endpoints?
4π
i found this useful and it works for me!
class CustomForm(forms.Form):
class Meta:
... #other properties such as model, fields, widgets and help text
labels = {
'comment' : '',
}
3π
You need to give False and it will work:
self.fields['mp_e'].label = False
django version: 2.2
- What's equivalent to Django's auto_now, auto_now_add in SQLAlchemy?
- Mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
1π
Go to your forms.py file and
add label = false
as
below
name = forms.CharField(required=True, max_length=100, widget=forms.TextInput(attrs={'placeholder': 'Enter Name *'}), label=False)
- How to use the admin autocomplete field in a custom form?
- Docker + Celery tells me not to run as root, but once I don't, I lack permissions to run
0π
Unless Iβm misunderstanding your question, you just need to add the mp_e field to the exclude tuple under the meta class. is this not what you need?
class MPForm( forms.ModelForm ):
def __init__( self, *args, **kwargs ):
super(MPForm, self).__init__( *args, **kwargs )
class Meta:
model = MeasurementPoint
exclude = ('mp_order','mp_e')
- How do I get the actual object id in a Django admin page (inside formfield_for_foreignkey)?
- ImportError: cannot import name "urandom"
- Django β show loading message during long processing
- Django QuerySet Custom Ordering by ID