5.3 Passing Python Variables to Be Rendered in the Template
This commit is contained in:
parent
81b586ac07
commit
c0661056cf
@ -9,6 +9,8 @@
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
|
||||
<table id="id_list_table"></table>
|
||||
<table id="id_list_table">
|
||||
<tr><td>{{ new_item_text }}</td></tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@ -17,4 +17,7 @@ class HomePageTest(TestCase):
|
||||
|
||||
def test_can_save_a_POST_request(self):
|
||||
response = self.client.post('/', data={'item_text': 'A new list item'})
|
||||
self.assertIn('A new list item', response.content.decode())
|
||||
self.assertIn('A new list item', response.content.decode())
|
||||
self.assertTemplateUsed(response, 'home.html')
|
||||
|
||||
|
@ -4,10 +4,6 @@ from django.shortcuts import render
|
||||
|
||||
# Create your views here
|
||||
def home_page(request):
|
||||
"""
|
||||
Using render function to take a request and name of the template to render
|
||||
"""
|
||||
|
||||
if request.method == 'POST':
|
||||
return HttpResponse(request.POST['item_text'])
|
||||
return render(request, 'home.html')
|
||||
return render(request=request, template_name='home.html', context={
|
||||
'new_item_text': request.POST['item_text'],
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user