Difficulty Rendering a Form

46 views
Skip to first unread message

Michael Starr

unread,
May 16, 2023, 2:55:28 PM5/16/23
to Django users
I am having difficulty rendering a form. Does anyone have a CONCISE tutorial for me?

Michael

Salaudeen Ridwan

unread,
May 16, 2023, 3:01:24 PM5/16/23
to django...@googlegroups.com
check corryshaffer tutorial on youtube 

On Tue, May 16, 2023, 7:54 PM Michael Starr <michaelst...@gmail.com> wrote:
I am having difficulty rendering a form. Does anyone have a CONCISE tutorial for me?

Michael

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/045cd9f2-20c2-4ecd-b5fe-409604d249fdn%40googlegroups.com.

Ammar Mohammed

unread,
May 16, 2023, 3:06:23 PM5/16/23
to 'Rahul Chauhan' via Django users
Hi Mr Starr
The documentation is very clear and helpful. 
Check the forms section 

Note that you should put your form variable in a double curly.... Like this :

<form>
{{ signup_form }}
<\form>

Regards 
Ammar Mohammed 
Whatsapp: 
        wa.me/249113075979 



On Tue, May 16, 2023, 20:55 Michael Starr <michaelst...@gmail.com> wrote:
I am having difficulty rendering a form. Does anyone have a CONCISE tutorial for me?

Michael

--

Michael Starr

unread,
May 18, 2023, 1:36:08 AM5/18/23
to Django users
I disagree. I think it's a mess. Also I'm banned from youtube for posting spoken word poems.

Thank you for being useless.

Mike

ALBERT ASHABA AHEEBWA

unread,
May 18, 2023, 4:21:07 AM5/18/23
to django...@googlegroups.com
Hi Mike,

Ammar was just trying to answer a question given so limited information.

With that in mind the best he could do was send you to the documentation. There was no need to be rude.

If you need any help, show what you have done, then show what you want done or desired outcome. Then people will be in a better position to help.

With regards to your question, there are various ways to solve it, forms were a problem to me till just recently.

So share a link to your repo and you will get the help you need. 



Best Regards,

Albert

Brian Gitau

unread,
May 18, 2023, 4:26:05 AM5/18/23
to django...@googlegroups.com
create a forms.py file

add into the file

import from django.forms import ModelForm
from .models import *

#the asterisk means you are importing everything from the models

class name_of_form(models.ModelForm):
         class Meta:
               model = your_model
               fields='__all__'

or 

   class name_of_form(models.ModelForm):
         class Meta:
               model = your_model
               fields=['field']


then in your templates you can render the form by

<form>
{{name_of_form}}
</form>


and you must add the form in the views.py file 

from .forms import *

#this is where your you want your form to be i.e under the function or class

form=name_of_your_form()

context={'form':form,}

the render it together with your template





On Tue, May 16, 2023 at 9:54 PM Michael Starr <michaelst...@gmail.com> wrote:
I am having difficulty rendering a form. Does anyone have a CONCISE tutorial for me?

Michael

--

ivan harold

unread,
Aug 9, 2023, 12:37:01 PM8/9/23
to Django users
from django import forms
 
# creating a form
class InputForm(forms.Form):
 
    first_name = forms.CharField(max_length = 200)
    last_name = forms.CharField(max_length = 200)
    roll_number = forms.IntegerField(
                     help_text = "Enter 6 digit roll number"
                     )
    password = forms.CharField(widget = forms.PasswordInput())
Let’s explain what exactly is happening, left side denotes the name of the field and to right of it, you define various functionalities of an input field correspondingly. A field’s syntax is denoted as
Syntax :
 

Field_name = forms.FieldType(attributes)
Now to render this form into a view, move to views.py and create a home_view as below.
 


from django.shortcuts import render
from .forms import InputForm
 
# Create your views here.
def home_view(request):
    context ={}
    context['form']= InputForm()
    return render(request, "home.html", context)
In view one needs to just create an instance of the form class created above in forms.py.
Now let’s edit templates > home.html
 


<form action = "" method = "post">
    {% csrf_token %}
    {{form }}
    <input type="submit" value=Submit">
</form>
Reply all
Reply to author
Forward
0 new messages