Home kellton

Main navigation

  • Services
    • Digital Business Services
      • AI & ML
        • Agentic AI Platform
        • Utilitarian AI
        • Predictive Analytics
        • Generative AI
        • Machine Learning
        • Data Science
        • RPA
      • Digital Experience
        • Product Strategy & Consulting
        • Product Design
        • Product Management
      • Product Engineering
        • Digital Application Development
        • Mobile Engineering
        • IoT & Wearables Solutions
        • Quality Engineering
      • Data & Analytics
        • Data Consulting
        • Data Engineering
        • Data Migration & Modernization
        • Analytics Services
        • Integration & API
      • Cloud Engineering
        • Cloud Consulting
        • Cloud Migration
        • Cloud Managed Services
        • DevSecOps
      • NextGen Services
        • Blockchain
        • Web3
        • Metaverse
        • Digital Signage Solutions
    • SAP
      • SAP Services
        • S/4HANA Implementations
        • SAP AMS Support
        • SAP Automation
        • SAP Security & GRC
        • SAP Value Added Solutions
        • Other SAP Implementations
      • View All Services
  • Platforms & Products
    • Audit.io
    • AiQ
    • Tasks.io
    • Optima
    • tHRive
    • Kellton4Health
    • Kellton4Commerce
    • KLGAME
    • Our Data Accelerators
      • Digital DataTwin
      • SmartScope
      • DataLift
      • SchemaLift
      • Reconcile360
    • View All Products
  • Industries
    • Fintech, Banking, Financial Services & Insurance
    • Retail, E-Commerce & Distribution
    • Pharma, Healthcare & Life Sciences
    • Non-Profit, Government & Education
    • Travel, Logistics & Hospitality
    • HiTech, SaaS, ISV & Communications
    • Manufacturing
    • Oil,Gas & Mining
    • Energy & Utilities
    • View All Industries
  • Our Partners
  • Insights
    • Blogs
    • Brochures
    • Success Stories
    • News / Announcements
    • Webinars
    • White Papers
  • Careers
    • Life At Kellton
    • Jobs
  • About
    • About Us
    • Our Leadership
    • Testimonials
    • Analyst Recognitions
    • Investors
    • Corporate Sustainability
    • Privacy-Policy
    • Contact Us
    • Our Delivery Centers
      • India Delivery Center
      • Europe Delivery Center
Search
  1. Home
  2. All Insights
  3. Blogs

Progressive enhancement with Django forms

Product Engineering
April 16 , 2018
Posted By:
Kellton
linkedin
Progressive enhancement with Django forms

Other recent blogs

Redefining Data Roles with Agentic AI
Redefining data roles with Agentic AI: What professionals must know
June 20 , 2025
AI in Cybersecurity
AI-powered cybersecurity: A way forward to proactive threat detection
June 19 , 2025
AI Vendors
Why vendor lock-in is riskier than ever in the GenAI era and what to do about it?
June 17 , 2025

Let's talk

Reach out, we'd love to hear from you!

Image CAPTCHA
Enter the characters shown in the image.
Get new captcha!

Batteries included Django, for better or worse, takes the approach of some web-frameworks such as Rails, and bundles as many utilities as necessary together with the core url-resolution framework, such as ORM, templating, administration, forms, and so on. This is in contrast to the philosophy of lighter-weight frameworks like Flask and platforms like node.js, which tend to take a more “mix-and-match” approach, encouraging the developer to pick out options for ORM, templating, forms, etc separately. A great deal can be said in favor of both approaches. While I prefer Django’s approach in general, one downside is it occasionally results in programmers fighting against the provided components instead of using them carefully and creatively.

Django Forms is sometimes a source of trouble. The default forms are ghastly, useless for modern UX concerns. Well-styled, flexible forms, with real-time validation and interactive, complicated widgets, are essential parts of a modern web app’s spec.

You might be tempted to completely disregard the forms feature, and just hardcode widgets in the templates, and pull in data from POST and validate data directly. While this is certainly a valid last resort or quick fix, it’s best to take advantage of the Django philosophy and do things in a well-structured and idiomatic way.

ms overview

Keep it simple

Graceful degradation to plain HTML forms for javaScript-impaired browsers may seem like a bit of a blast from the past: there aren’t too many web users left without javaScript in today’s web. However, this philosophy of implementation is particularly suited toward building easily readable and portable web applications in Django.

So, how do we do fancy custom widgets in Django forms, while still being able to do {{ form.as_p }}, or the equivalent? Depending on the level of customization needed, we can use the following process:

  • So, how do we do fancy custom widgets in Django forms, while still being able to do {{ form.as_p }}, or the equivalent? Depending on the level of customization needed, we can use the following process:
  • Not enough? Do you have some pre-baked javaScript, such as from bootstrap, to toss in there? Using widget attributes, we can invoke JS enhancements on a plain Django field.
  • Need some custom JS enhancements? One thing to do, then, is attach a data-do-something sort of attribute to the widget, and then somewhere in your included javaScript add the enhancement (e.g. $('[data-do-something]').each(function () { ... })), or perhaps just make the widget a hidden input, and put your JS and HTML in a template snippet.
  • At this point, you’ll probably need some custom validation or data processing. That’s easy enough too: go ahead and implement some clean_* fields on your form, or even create a custom FormField which correctly cleans and parses your data type.
  • Finally, if you truly hit a wall with the generated HTML, which you likely will with at least one form, it’s time to write a custom widget! Writing custom widgets can include arbitrary python-generated HTML, completely obsoleting hardcoded HTML forms. If you don’t like the idea of including embedded HTML in python, then include the render_to_string shortcut.

Of course, if you go through this process, and still feel you are struggling against Django instead of taking advantage of the power and flexibility of Django forms, then you might really be hitting a limitation with the framework, and throwing in some custom HTML and validation code won’t hurt in a pinch. However, I’ve found this a very rare circumstance. Using the above options, you can predictably produce re-usable components that are easily readable by other Django engineers.

Want to know more?

5 biggest quality assurance and mobile testing challenges
Blog
5 biggest quality assurance and mobile testing challenges for app development: Quick strategies to solve them
June 16 , 2025
Testing AI applications and ML models
Blog
Testing AI applications and ML models: Revealing proven quality assurance strategies and techniques
June 11 , 2025
B2B ecommerce trends
Blog
Top Ecommerce Trends 2025: Stay Ahead in the Digital Market
June 05 , 2025

North America: +1.844.469.8900

Asia: +91.124.469.8900

Europe: +44.203.807.6911

Email: ask@kellton.com

Footer menu right

  • Services
  • Platforms & Products
  • Industries
  • Insights

Footer Menu Left

  • About
  • News
  • Careers
  • Contact
LinkedIn LinkedIn twitter Twitter Youtube Youtube
Recognized as a leader in Zinnov Zones Digital Engineering and ER&D services
Kellton: 'Product Challenger' in 2023 ISG Provider Lens™ SAP Ecosystem
Recognized as a 'Challenger' in Avasant's SAP S/4HANA services
Footer bottom row seperator

© 2025 Kellton