开发者

How to remove inputs/fields created by a form in Django

I have a simple form for uploading a profile picture and then a thumbnail image showing what has been uploaded. The HTML code is:

<form action="{% url 'base-welcome' %}" enctype="multipart/form-data" method="post">
    {% csrf_token %}
<ul>
<li><span>Upload A Profile Picture:</span> <img src="{{ user.profile.get_thumbnail }}">{{ profile_form.picture }}</li> , then closing elements, etc..

The problem is that the form is creating unwanted elements in the "li". See the following image:

How to remove inputs/fields created by a form in Django

开发者_运维问答

The "currently" and "change" have been created. I've already hidden a checkbox that was created using display: none. I can't really do that with these elements because they are just text that was generated.

I think this is a problem with the models.py/views.py pages, but I may be wrong. Just looking for a simple HTML/CSS fix. Thank you so much!!


It looks like picture field is using ClearableFileInput widget. To use standard FileInput widget (without these extra words and checkbox), do just in your form:

picture = forms.ImageField(upload_to='/path/', widget=forms.FileInput)


In that case you just have to render your forms manually :)

You could either write your own helpers - I can see this as ie. custom filters: {{ form.field|as_file_input_field }} or you could use some external helpers like: http://djangopackages.com/grids/g/forms/

I would still suggest writing your own helpers just to learn how django forms renderer works :)

You could also take a look here for some samples of how we tried to solved this problem while before: https://github.com/efabryka/django-template_widgets :)

This is how the ImageField default widget is rendered - maybe it will be worth your while: https://github.com/django/django/blob/master/django/forms/widgets.py#L298


Are you just wanting to hide some text? I haven't touched HTML/CSS in a while but can't you just put the text inside a div or a span and then hide that?


set color: white; for that element, then all text will be "invisible" lol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜