I created a form to collect users emails, phone numbers, and their names of course, the form fields are not showing in my html page only the submit button is showing
here are models
from django.db import models
# Create your models here.
class User(models.Model):
name = models.CharField(max_length=15)
email = models.EmailField()
phone = models.CharField(max_length=10)
forms.py
from django.forms import ModelForm
from landing_page.models import User
class UsersDataForm(ModelForm):
class Meta:
model = User
fields = ['name','email','phone']
views
from django.core.exceptions import ValidationError
from django.shortcuts import render, redirect
from django.core.validators import validate_email
from .forms import UsersDataForm
# Create your views here.
def home(request):
return render(request, 'home.html')
def users_data(request):
if(request.method == 'POST'):
form = UsersDataForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
try:
validate_email(email)
except ValidationError:
form.add_error('email', 'تأكد من الايميل الذي ادخلته')
if not form.errors:
form.save()
form = UsersDataForm()
return redirect('home', {'form': form})
else:
form = UsersDataForm()
return render(request, 'home.html', {'form': form})
template
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">تسجيل</button>
</form>
Chrome developer tools