Django Material Widgets

Easily convert your Django Forms and ModelForms to use widgets styled with Material Components for the Web.

status docs pypi pyversion license

Click to view demo

Quick Start

  1. Install Django Material Widgets:

    pip install django-material-widgets
    
  2. Edit your forms.py:

    • Import material_widgets.widgets.MaterialForm and/or material_widgets.widgets.MaterialModelForm:

      from material_widgets import MaterialForm, MaterialModelForm
      
    • Change forms using django.forms.Form and/or django.forms.ModelForm to MaterialForm or MaterialModelForm respectively:

      class MyForm(forms.Form): ⇨ class MyForm(MaterialForm):
      
      class MyModelForm(forms.ModelForm): ⇨ class MyModelForm(MaterialModelForm):
      
  3. Edit your HTML templates:

    • Change {{ form }} template variables to {{ form.as_components }}:

      {{ form.as_p }} ⇨ {{ form.as_components }}
      
    • Add {{ form.media.css }} to your <head> tag:

      <head>
          {{ form.media.css }}
      </head>
      
    • Add the mdc-typography css class to your <body> tag:

      <body class="mdc-typography">
      
    • Add {{ form.media.js }} to the bottom of your <body> tag:

      <body class="mdc-typography">
          ...
      
          {{ form.media.js }}
      </body>
      
    • (Optional) Add stylesheet links:

      <head>
          <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
          <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
      </head>
      

Demo

https://demo.github.com

To view the demo locally at http://localhost:8000:

git clone https://github.com/ooknosi/django-material-widgets.git
cd django-material-widgets/src
python manage.py migrate --settings=demo.settings
python manage.py runserver --settings=demo.settings