Aadish Shele
Aadish Shele

Reputation: 23

Is there a way to take a variable from one html file and use it in another

I have this code which takes the name into the "nm" variable

{% extends "base.html" %}
{% block title %}Search Page{% endblock %}

{% block content %}
<form action="#" method="post">
    <p>User or Group:</p>
    <p><input type="text" name="nm"/></p>
    <p><input type="submit" value="submit"/></p>
    
</form>
{% endblock %}

I want to put this variable into a different html file which will show different things. Can anyone suggest me the most efficient way to make this happen?

Upvotes: 2

Views: 62

Answers (1)

Robo
Robo

Reputation: 733

If you're using Django, send the nm text field back to your view in views.py, where you should access that variable (nm = request.POST.get("nm")) and then send that via the context variable in the render() function to your other HTML file (return render(request, "your_other_file.html", {"nm": nm})), where you can access the variable via interpolation ({{ nm }})

Upvotes: 1

Related Questions