In the form template tag, shouldn’t it be {{ form.as_p}} tag? On Sat 4. Apr 2020 at 3.35, Ifeanyi Chielo <ifeanyi.chi...@unn.edu.ng> wrote:
> Hello,I developed a form with a single field, but this form displays only > the submit button at the browser as shown in the image below. Please how > can I correct this and also save the field to the MySQL table. My code is > also shown below > > [image: django form.png] > > View.py > > from django.http import HttpResponseRedirect > > from django.shortcuts import render > > from .models import Namerec > > from .forms import NameForm > > from django.views.generic import TemplateView > > > > def HomePageView (request, *args, **kwargs): > > return render(request,"home.html", {}) > > def Namev_view (request): > > if request.method == 'POST': > > form = NameForm (request.POST) > > if NameForm.is_valid(): > > NameForm.save() > > context = { > > 'form': form > > } > > return render(request, 'namev.html', {}) > > form.py > > from .models import Namerec > > from django import forms > > class NameForm(forms.Form): > > your_name = forms.CharField(label='Your name', max_length=100) > > template (namev.htlm) > > <form action="/namev/" method="Post"> > > {% csrf_token %} > > {{ form }} > > <input type="submit" value="Submit"> > > </form> > > > > > > Model.py > > from django.db import models > > class Namerec(models.Model): > > your_name = models.CharField(max_length=30) > > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/f50577dd-d5c0-4478-8993-7bab533f24f9%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/f50577dd-d5c0-4478-8993-7bab533f24f9%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAipwd8nHw9WeLmhG2Eo7o5NztkJZ7xWSLa8d%3D-1_yiVjw6CrQ%40mail.gmail.com.