Chief Programmer,
ICT Unit, UNN
Send screen short--Le sam. 4 avr. 2020 à 11:33, Ifeanyi Chielo <ifeanyi.chielo@unn.edu.ng> a écrit :Thanks a lot,I did as you said and I encountered the error message below:UnboundLocalError at /namev/
local variable 'form' referenced before assignment
Request Method: GET Request URL: http://localhost:8000/namev/ Django Version: 2.1.5 Exception Type: UnboundLocalError Exception Value: local variable 'form' referenced before assignmentException Location: C:\Users\IFEANYI CHIELO\divinecrownapp\pages\views.py in Namev_view, line 42 Python Executable: C:\Users\IFEANYI CHIELO\AppData\Local\Programs\Python\Python37\python.exe Python Version: 3.7.2 Python Path: ['C:\\Users\\IFEANYI CHIELO\\divinecrownapp', 'C:\\Users\\IFEANYI ' 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip', 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\DLLs', 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib', 'C:\\Users\\IFEANYI CHIELO\\AppData\\Local\\Programs\\Python\\Python37', 'C:\\Users\\IFEANYI ' 'CHIELO\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']Server time: Sat, 4 Apr 2020 11:27:07 +0000 Dr. Chielo C. Ifeanyi
Chief Programmer,Head Webometrics Section
ICT Unit, UNN--On Sat, Apr 4, 2020 at 10:09 AM Luqman Shofuleji <luqmanshof@gmail.com> wrote:--In def Namev_view under views.py, include form in the return parameter and see if that resolves the issuereturn render(request, 'namev.html', {'form':form})On Sat, Apr 4, 2020, 1:35 AM Ifeanyi Chielo <ifeanyi.chielo@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 belowView.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+unsubscribe@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.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHyB84rUTDyiba%2B%2Bvk%3DJFuRN7CPBPTpso2JvyBc28Q4gG-faYg%40mail.gmail.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOcS8H1YiVcABEXBEa5-qEu4V4NBeGfY3PkFa%3DYCf9OEdUAO-Q%40mail.gmail.com.
--La meilleure façon de prédire l'avenir est de le créer.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANoHCsuxMoGCQ9GNi5xa%2BYoNLnE8dwKMuh%2BXCvG_swxaZ_uT6g%40mail.gmail.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOcS8H2cdY9KF4WX26MjhgQXrUKP%2Bb7NjCyO28TwbJ5cFWHWmg%40mail.gmail.com.

No comments:
Post a Comment