<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tdvr</title>
    <description>The latest articles on DEV Community by tdvr (@tdvr).</description>
    <link>https://dev.to/tdvr</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F287067%2F56b75a7b-349b-4c7b-97da-733a5a88bc80.jpg</url>
      <title>DEV Community: tdvr</title>
      <link>https://dev.to/tdvr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tdvr"/>
    <language>en</language>
    <item>
      <title>Easy way to customize Django Forms</title>
      <dc:creator>tdvr</dc:creator>
      <pubDate>Wed, 29 Dec 2021 12:34:24 +0000</pubDate>
      <link>https://dev.to/tdvr/easy-way-to-customize-django-forms-55g2</link>
      <guid>https://dev.to/tdvr/easy-way-to-customize-django-forms-55g2</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MUDqRhdI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xla3lw0j6012wcm79932.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MUDqRhdI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xla3lw0j6012wcm79932.jpg" alt="Cover photo, before and after" width="880" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A quick and simple overview to Bootstrap and style your Django forms.&lt;/p&gt;

&lt;p&gt;I had to go through this recently. I read many threads and comments around asking the same questions, so I guess a simple thread wouldn't be bad for anyone who just starts using Django.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.    Install django-widget-tweaks and Bootstrap.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can install it through &lt;a href="https://pypi.org/project/django-widget-tweaks/"&gt;pip&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ pip install django-widget-tweaks&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Import Bootstrap and django-widget-tweaks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the settings.py of your Django project, find INSTALLED_APPS and insert &lt;code&gt;widget_tweaks&lt;/code&gt; there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rt7X_sD6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k33101mgtcmwn42hj2mp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rt7X_sD6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k33101mgtcmwn42hj2mp.png" alt="Image description" width="309" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To import Bootstrap, just visit the &lt;a href="https://getbootstrap.com"&gt;official page&lt;/a&gt;, click Get Started and copy the stylesheet &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; into your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; of your base.html which is used for template extending in Django. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GDcPWasV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3xstvnwbbgh8zdyqvqv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GDcPWasV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3xstvnwbbgh8zdyqvqv.png" alt="Image description" width="500" height="156"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;3.    Load widget_tweaks to your template.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Insert &lt;code&gt;{% load widget_tweaks %}&lt;/code&gt; to your template.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gFDx2O9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9zron7dqjycshavxouw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gFDx2O9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s9zron7dqjycshavxouw.png" alt="Image description" width="242" height="69"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;4.    Use render_field template tag&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;render_field&lt;/code&gt; template tag provides the ability to customize any form field easily with HTML attributes and CSS classes. The complete list of features appear on the official repository of the package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% render_field form.username class="form-control" placeholder="Username" %}
    ...
    ...
{% render_field form.password2 class="form-control" id="PassConf" placeholder="Confirm Password" %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;5 Some CSS to style your forms as you please.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.form-control{
    border: 1px solid rgba(65, 65, 65, 0.91);
    box-shadow: 0 0 0 0.15rem rgba(0, 0, 0, 0.25);
}
.form-control:hover {
    border: 1px solid rgb(184, 69, 241);
    box-shadow: 0 0 0 0.25rem rgba(192, 112, 246, 0.64);
}

.form-control:focus {
    border: 1px solid rgb(0, 127, 244, 1);
    box-shadow: 0 0 0 0.25rem rgb(0, 127, 244, 0.45);
}

#PassConf {
    border: 1px solid rgb(92, 241, 69);
    box-shadow: 0 0 0 0.2rem rgba(112, 246, 166, 0.64);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Source code and all the customization options:   &lt;a href="https://github.com/jazzband/django-widget-tweaks/"&gt;https://github.com/jazzband/django-widget-tweaks/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>forms</category>
      <category>bootstrap</category>
      <category>style</category>
    </item>
  </channel>
</rss>
