Uploadfile form and CSS Style

181 views
Skip to first unread message

Russo

unread,
Nov 13, 2014, 2:44:35 PM11/13/14
to django...@googlegroups.com
Hi,

i just implemented the uploadfile form on Django, and everything goes
greate, but i would like to do if it is possible to apply CSS styles to
the upload botton on the forms, Anybody knows this?

Regards
Russo

Kakar Nyori

unread,
Nov 13, 2014, 3:08:18 PM11/13/14
to django...@googlegroups.com
Then you need to apply css to the form.


Russo

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54650A9B.8040004%40musicparticles.com.
For more options, visit https://groups.google.com/d/optout.

Russo

unread,
Nov 13, 2014, 3:14:12 PM11/13/14
to django...@googlegroups.com
Hi Kakar,

but i tried and there is not way to change the bottom style, see the html code

        <!-- Upload form. Note enctype attribute! -->
        <form action="{% url "list" %}" method="post" enctype="multipart/form-data">
            {% csrf_token %}

            <p>{{ form.non_field_errors }}</p>
            <p>{{ form.docfile.label_tag }} {{ form.docfile.help_text }}</p>
            <p>
                {{ form.docfile.errors }}
                {{ form.docfile }}
            </p>
            <p><input type="submit" value="Upload" /></p>
        </form>

as it is a form there is no way to change style ¿?

Regards/AR



El 13/11/2014 a las 03:37 p.m., Kakar Nyori escribió:
Then you need to apply css to the form.
On Fri, Nov 14, 2014 at 1:16 AM, Russo <arus...@musicparticles.com> wrote:
Hi,

i just implemented the uploadfile form on Django, and everything goes greate, but i would like to do if it is possible to apply CSS styles to the upload botton on the forms, Anybody knows this?

Regards

Russo

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54650A9B.8040004%40musicparticles.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

James Schneider

unread,
Nov 13, 2014, 3:18:16 PM11/13/14
to django...@googlegroups.com

If you are manually expressing the form, then you can add classes and ID's to any or all elements in the form. Even if you are using something like the {{ form.as_p }} method to display the form, you can still style it using CSS styles at the tag level. Just include a custom CSS file with your template.

-James

Russo

unread,
Nov 17, 2014, 8:00:54 AM11/17/14
to django...@googlegroups.com
Hi James,

sorry I'm new on Django, can you give me some code example? I mean, hot to define the CLASS or ID into the html with elements like this {{ form.docfile }} ?

Regards
Russo

Collin Anderson

unread,
Nov 17, 2014, 4:51:45 PM11/17/14
to django...@googlegroups.com
Hi Russo,

There should be an auto-generated id, in this case probably #id_docfile for that field. You could check the generated html source to be sure. (or "Inspect Element" in a browser.)

Collin

donarb

unread,
Nov 17, 2014, 7:42:53 PM11/17/14
to django...@googlegroups.com
I assume you have a form class for your form. In that class file, you can define the class or any other attribute that is used by that widget in your form, something like this (note, this is sort of off the top of my head, but you should be able to get the idea):

class MyForm(forms.Form):
    upload = forms.FileField(widget=forms.FileInput(attrs={'class': 'some_style' }))

Kakar Nyori

unread,
Nov 18, 2014, 3:43:45 AM11/18/14
to django...@googlegroups.com
Hello Russo,

You need to select the input button in the css. Something like this:

input[type=submit] {
background-color: transparent;
border:none;
cursor:pointer;
background-color:blue;
color:white;
}

Note that this will select every "submit" type button in your html. So if you don't want all of them to be like the above, then you need to provide the ID and and then select the submit button. You can check it by the inspect element tool, as Collin has described. Or you can manually do it in your forms as Donarb has described.

Hope this will make some sense.

Cheers!

Reply all
Reply to author
Forward
0 new messages