“Django Forms” Réponses codées

Passer la soumission du formulaire de Django de l'utilisateur

if form.is_valid():
    post = form.save(commit=False)
    post.author = request.user
    post.published_date = timezone.now()
    post.save()
Bored Bison

Exemple de formulaire de django

from django import forms

# creating a form
class SampleForm(forms.Form):
	name = forms.CharField()
	description = forms.CharField()
Unsightly Unicorn

django obtenir un formulaire ID de la demande

# html
<input type="submit" value="Reply" name ="message_frm">

# views.py
if 'message_frm' in request.POST:
    #do somethings 
Repulsive Raven

Django Forms

from django import forms
        
class FormName(forms.Form):
         # each field would be mapped as an input field in HTML
        field_name = forms.Field(**options)
vip_codes

Django Forms

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User


# Create your forms here.
class NameForm(forms.Form):
    your_name = forms.CharField(label='Your name', max_length=100)
OHIOLee

Réponses similaires à “Django Forms”

Questions similaires à “Django Forms”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code