Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 979935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:17:54+00:00 2026-05-16T04:17:54+00:00

I am a current web2py user, but find I still go back to Django

  • 0

I am a current web2py user, but find I still go back to Django once in a while (where I started). Specifically when working on projects where I want to make use of some specific django apps/plugins/extensions that don’t yet exist in web2py.

One thing that I can’t live without in web2py, which I am looking for a solution for in Django, is the way to create html forms from a db table and being able to then customize their look and layout in the view, without javascript.

Key things I am looking for:

  1. Generate html form from a db table
  2. Assign custom css classes/ids to each field in the generated html form (js disabled)
  3. Place each form field/element in a pre-made html view via a method call in the view

i.e.

I have a table A. In web2py I can do (in controller):

def display_form():
   form = SQLFORM(db.table_A)
   #Can I do the following in Django? Assign custom CSS to each form field?
   form.element(_name='email')['_class'] = = "custom_css_classes, list"

   if form.accepts(request.vars, session):
       response.flash = 'form accepted'
   elif form.errors:
       response.flash = 'form has errors'
   else:
       response.flash = 'please fill out the form'
   return dict(form=form)

Then, in the View I can do:

form.custom.start
form.custom.widget.name
form.custom.widget.email
form.custom.widget.form_field_name
           ...
<div class="span-5 last"><input type="submit" class="register_btn" value="Sign Up"></input></div>
form.custom.end

The above takes a DB table, creates an HTML form, and then lets me stick each separate form field in any place in the pre-made HTML that I want (using those “custom” method calls on the passed “form” object. Including the custom css classes I assigned to each separate field of the generated html form.

See documentation for details on the above code:

http://web2py.com/book/default/chapter/06?search=define_table

http://web2py.com/book/default/chapter/07?search=sqlform#SQLFORM

http://web2py.com/book/default/chapter/05?search=#Server-side-DOM-and-Parsing

http://web2py.com/book/default/chapter/07?search=form.custom

How do I do the above in Django without dirtying my javascript with layout hacks. Assume javascript is disabled in the browsers where I need my app to run. Furthermore, I would love to make use of Django admin. Pylons solutions also welcome!

Links to articles/tutorials/howtos for this would be greatly appreciated.
Also, please make an equivalent result of the above code using the method you mention in your response…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:17:55+00:00Added an answer on May 16, 2026 at 4:17 am

    Use ModelForm and override any field you wanna customize by explicitly declaring them.

    If you want to set field attributes like class and id, you need to do something like this:

    name = forms.CharField(
                    widget=forms.TextInput(attrs={'class':'special'}))
    

    In case you are interested, you may change the order of the fields by specifying a fields sequence in your Meta class:

    class Meta:
        model = YourModel
        fields = ('title', 'content')
    

    You may read the full documentation here:
    http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
My current setup.py script works okay, but it installs tvnamer.py (the tool) as tvnamer.py
My current app needs to store address information for a user. I'm currently debating
Current solution: user clicks on label and it is switched with a textarea to
Current database have 200 thousand record. I want to make iPad application , can
Current, I've got a stored procedure that has a main goal of doing a
My current development project has two aspects to it. First, there is a public
My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio
My current view is no, prefer Transact SQL stored procedures because they are a
My current place of employment is currently in a transition, new ownership has taken

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.