python - Django KeyError at /name/ in Django Form -


I'm trying to get the name and surname value and print the HTML. This is my code: import from django.shortcuts import from django.shortcuts

  import. Import from import from Django.http import from HTTP Email Email. Import the model from renginiai.forms import Vartotojas VartotojasForm def name (request): If request.method == 'GET': form = VartotojasForm (request.GET) name = form.data ['name'] surname = form.data [ Submit 'return' (request, 'vartotojas (' format ': form,' name ': name,' surname ': surname}) Other: form = vartosages form () submission of return (request, vatotoseas-form 1 9 ', {' form ': form})  

Vartotojas-form.html

   gt; Top & gt; ; & Gt; Title & gt; Names & lt; / title & gt; & lt; / head & gt; & lt; body & gt; & lt; h1 & gt; Names & lt; / h1 & gt; & Lt ; Form action = "sumbit" Method = "get" & gt; Table & gt; {{Form.as_table}} & lt; / table & gt; {% Csrf_token%} & lt; input type = "submit" value = "submit "& Gt; & lt; / form & gt; & lt; / body & gt;  

Where is my fault I'm getting keyError

Try this:

  def name (request): If request.method == 'POST': form = VartotojasForm (request.POST) if form.is_valid (): name = form.cleaned_data ['name'] surname = form.cleaned_data ['surname'] Return submission (request , 'Vartotojas-result.html', {'form': form, 'name': name, 'surname': surname}): form = VartotojasForm () return render (request, 'vartotojas-form.html', << F Change this to: orm>: )  
< name :

 : Form, 'name': name,  

{'form': form, 'name': name, 'surname': surname}

and your < Change the code> Vertostose-form HTML form to:

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Name & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H1 & gt; Name & lt; / H1> & Lt; Form action = "symbol" method = "post" & gt; & Lt; Table & gt; {{Form.as_table}} & lt; / Table & gt; {% Csrf_token%} & lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt;  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -