Send screen short

Le sam. 4 avr. 2020 à 11:33, Ifeanyi Chielo <ifeanyi.chi...@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 assignment
>
> Exception 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
> 08032366433, 08154804230
> ifeanyi.chi...@unn.edu.ng
> http://www.unn.edu.ng/users/ifeanyichielo <http://www.unn.edu.ng>
>
>
>
> On Sat, Apr 4, 2020 at 10:09 AM Luqman Shofuleji <luqmans...@gmail.com>
> wrote:
>
>> In def Namev_view under views.py, include form in the return parameter
>> and see if that resolves the issue
>>
>> return render(request, 'namev.html', {'form':form})
>>
>>
>>
>> On Sat, Apr 4, 2020, 1:35 AM 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/CAHyB84rUTDyiba%2B%2Bvk%3DJFuRN7CPBPTpso2JvyBc28Q4gG-faYg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAHyB84rUTDyiba%2B%2Bvk%3DJFuRN7CPBPTpso2JvyBc28Q4gG-faYg%40mail.gmail.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/CAOcS8H1YiVcABEXBEa5-qEu4V4NBeGfY3PkFa%3DYCf9OEdUAO-Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOcS8H1YiVcABEXBEa5-qEu4V4NBeGfY3PkFa%3DYCf9OEdUAO-Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
-- 
*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+unsubscr...@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.

Reply via email to