I am using django to create a web app. I have run into a problem when trying to use variables from python in html. The variable does not show up. The app has a lot of messy code so I have recreated the problem including only relevant files.
views.py:
from django.shortcuts import render
# Create your views here.
def home(request):
return render(request, 'main/index.html')
def hello(request):
if request.method == 'POST':
fname = request.POST.get('fname', None)
else:
fname = "there"
return render(request, 'main/hello.html')
index.html:
{% extends "base.html" %} {% block content %}
<form action="hello" method="POST">
{% csrf_token %}
<input name="fname" placeholder="First Name">
<input type="submit" value="Submit">
</form>
{% endblock content %}
hello.html
{% extends "base.html" %} {% block content %}
<p>Hello {{fname}}</p>
{% endblock content %}
base.html:
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="{% static "css/style.css" %}">
</head>
<body>
{% block content %}{% endblock content %}
</body>
</html>
Here is what the "hello" page looks like(only part of the screen):

I want it to be able to output the users input.
render(..)call.fnamewas defined in the "hello" function. It doesn't magically exist anywhere else.