Quantcast

ModelForms

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

ModelForms

Scott Macri-2
I think I shot myself in the foot using ModelForms to generate all of my html forms.  Is there any way to use a stylesheet when your forms are generated from ModelForms?

I've tried everything and cannot get it to work.  I've tried directly importing the css files, I've tried loading them from STATIC, and I've tried setting css in Meta, but nothing seems to work.  All I have to do is add some color to my tables and align the text to the left of the cells.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/d_3ry3L6DuEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

Mario Gudelj-2
It doesn't matter how you generate your form, your CSS should be applied from inside the template. You need to add a CSS file link to a template to which you're passing the form to inside your context from within a view, or you can embed it into your template using <style> tags.

On 23 March 2012 09:46, hack <[hidden email]> wrote:
I think I shot myself in the foot using ModelForms to generate all of my html forms.  Is there any way to use a stylesheet when your forms are generated from ModelForms?

I've tried everything and cannot get it to work.  I've tried directly importing the css files, I've tried loading them from STATIC, and I've tried setting css in Meta, but nothing seems to work.  All I have to do is add some color to my tables and align the text to the left of the cells.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/d_3ry3L6DuEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

Tim Ney
I think the best thing for you do is to create the css outside the template. Like this - create the css file, separately, then reference the file in the template.
 
Or, better yet, add the css you need for your form in you main css file that is referenced in your base template and just inherit it by
using a tag {{ extends "base.html""}, then you will have a uniform look throughout the site and you won't have to worry about but once.


 
On Fri, Mar 23, 2012 at 3:10 AM, Mario Gudelj <[hidden email]> wrote:
It doesn't matter how you generate your form, your CSS should be applied from inside the template. You need to add a CSS file link to a template to which you're passing the form to inside your context from within a view, or you can embed it into your template using <style> tags.


On 23 March 2012 09:46, hack <[hidden email]> wrote:
I think I shot myself in the foot using ModelForms to generate all of my html forms.  Is there any way to use a stylesheet when your forms are generated from ModelForms?

I've tried everything and cannot get it to work.  I've tried directly importing the css files, I've tried loading them from STATIC, and I've tried setting css in Meta, but nothing seems to work.  All I have to do is add some color to my tables and align the text to the left of the cells.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/d_3ry3L6DuEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

Kurtis Mullins-2
If you're worried about stylizing specific fields, it'll be setup as a table, ul, or paragraph based upon how you "render the form" (paragraph by default I think). The individual fields are named with the following convention (if I recall correctly) <input id="id_<field_name>" ... />. So for a field named "password" in a paragraph rendered form, it'll end up sort of like this:

<p><label for="id_password">password</label><input type="password" name="password" id="id_password" /></p>

Of course I don't use these pre-rendered forms because mine typically need too much customization. So what we do is the following:

<form action="" method="post">{% csrf_token %}
...
<input name="password" type="password" value="{{ form.password.value }}" />
<input type="submit" value="Click Me!" />
...
</form>

and you can easily add in your own stylizing CSS and elements as needed.

On Fri, Mar 23, 2012 at 12:25 PM, Tim Ney <[hidden email]> wrote:
I think the best thing for you do is to create the css outside the template. Like this - create the css file, separately, then reference the file in the template.
 
Or, better yet, add the css you need for your form in you main css file that is referenced in your base template and just inherit it by
using a tag {{ extends "base.html""}, then you will have a uniform look throughout the site and you won't have to worry about but once.


 
On Fri, Mar 23, 2012 at 3:10 AM, Mario Gudelj <[hidden email]> wrote:
It doesn't matter how you generate your form, your CSS should be applied from inside the template. You need to add a CSS file link to a template to which you're passing the form to inside your context from within a view, or you can embed it into your template using <style> tags.


On 23 March 2012 09:46, hack <[hidden email]> wrote:
I think I shot myself in the foot using ModelForms to generate all of my html forms.  Is there any way to use a stylesheet when your forms are generated from ModelForms?

I've tried everything and cannot get it to work.  I've tried directly importing the css files, I've tried loading them from STATIC, and I've tried setting css in Meta, but nothing seems to work.  All I have to do is add some color to my tables and align the text to the left of the cells.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/d_3ry3L6DuEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

Tim Ney
Not to gild the lilly, but, you could also do this, and it would work: either as part of the css you are inheriting from the "base" or, separately, you could create a whole slew of named css styles in one file, then apply each file to the template tags, table tags you use to call the data into the template as you see fit, you could then modify the css rther easily to get the appearance you want. I don't know if this helps, or not, but all my static files, css, javascript are called up by a separate server, not apache, and if you don't have all the urls right, no static file, css renders.

On Fri, Mar 23, 2012 at 12:34 PM, Kurtis Mullins <[hidden email]> wrote:
If you're worried about stylizing specific fields, it'll be setup as a table, ul, or paragraph based upon how you "render the form" (paragraph by default I think). The individual fields are named with the following convention (if I recall correctly) <input id="id_<field_name>" ... />. So for a field named "password" in a paragraph rendered form, it'll end up sort of like this:

<p><label for="id_password">password</label><input type="password" name="password" id="id_password" /></p>

Of course I don't use these pre-rendered forms because mine typically need too much customization. So what we do is the following:

<form action="" method="post">{% csrf_token %}
...
<input name="password" type="password" value="{{ form.password.value }}" />
<input type="submit" value="Click Me!" />
...
</form>

and you can easily add in your own stylizing CSS and elements as needed.

On Fri, Mar 23, 2012 at 12:25 PM, Tim Ney <[hidden email]> wrote:
I think the best thing for you do is to create the css outside the template. Like this - create the css file, separately, then reference the file in the template.
 
Or, better yet, add the css you need for your form in you main css file that is referenced in your base template and just inherit it by
using a tag {{ extends "base.html""}, then you will have a uniform look throughout the site and you won't have to worry about but once.


 
On Fri, Mar 23, 2012 at 3:10 AM, Mario Gudelj <[hidden email]> wrote:
It doesn't matter how you generate your form, your CSS should be applied from inside the template. You need to add a CSS file link to a template to which you're passing the form to inside your context from within a view, or you can embed it into your template using <style> tags.


On 23 March 2012 09:46, hack <[hidden email]> wrote:
I think I shot myself in the foot using ModelForms to generate all of my html forms.  Is there any way to use a stylesheet when your forms are generated from ModelForms?

I've tried everything and cannot get it to work.  I've tried directly importing the css files, I've tried loading them from STATIC, and I've tried setting css in Meta, but nothing seems to work.  All I have to do is add some color to my tables and align the text to the left of the cells.  Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/d_3ry3L6DuEJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

Eryn Wells
In reply to this post by Scott Macri-2
On Thu, Mar 22, 2012 at 3:46 PM, hack <[hidden email]> wrote:
> I think I shot myself in the foot using ModelForms to generate all of my
> html forms.  Is there any way to use a stylesheet when your forms are
> generated from ModelForms?

You should be able to render the forms and plug the rendered HTML into
a template, which will let you do whatever you want in terms of
including style sheets and such...

How have you been trying to do it?

Eryn

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ModelForms

bruno desthuilliers-7
In reply to this post by Scott Macri-2
On Mar 23, 12:46 am, hack <[hidden email]> wrote:
> I think I shot myself in the foot using ModelForms to generate all of my
> html forms.  Is there any way to use a stylesheet when your forms are
> generated from ModelForms?

Yes of course, why ?

> I've tried everything and cannot get it to work.  I've tried directly
> importing the css files, I've tried loading them from STATIC, and I've
> tried setting css in Meta, but nothing seems to work.

Your problem is with serving the css files, not with Django's form.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Loading...