0

I am new to django. My current plan is displaying user name on different html pages, once user have successfully logged in. At the moment, the page after login page can successfully display the user name with the django tag in html which is {{ username }}. But once it has successfully passed to my second page, my second page CAN NOT pass it to my third page. The attached images are my html codes for second.html and third.html. Thanks for your help.

Second.html

 <form action="/SecondPageSub/" method="POST">
    {% csrf_token %}<br>
    <b>NTID:</b><br>
    <label name="usrnm">{{username}}</label>
    <button type="submit" name="SecondPageSub">
    SUBMIT
    </button>
</form>

Third.html

     <form action="/ThirdPageSub/" method="POST">
        {% csrf_token %}<br>
        <b>NTID:</b><br>
        <label name="usrnm">{{username}}</label>
        <button type="submit" name="ThirdPageSub">
        SUBMIT
        </button>
    </form>

Python codes in view.py

    def ActionGet(request):
        if request.method == "POST":
            if 'login' in request.POST:
                usrname = request.POST.get("usrnm", None)
                passwrd = request.POST.get("pwd", None)
                dic={}
                dic['username']=usrname
                dic['password']=passwrd
                return render(request, "Second.html",dic)

            if 'SecondPageSub' in request.POST:
                usrname = request.POST.get("usrnm", None)
                dic={}
                dic['username']=usrname
                return render(request, "Third.html",dic)

            if 'ThirdPageSub' in request.POST:
                usrname = request.POST.get("usrnm", None)
                dic={}
                dic['username']=usrname
                return render(request, "Forth.html",dic)
3
  • Please post code instead of screenshots. Commented Dec 24, 2019 at 9:46
  • What do your urls look like? Commented Dec 24, 2019 at 9:47
  • I have attached html code instead of screenshots. Thank you for any help! Commented Dec 24, 2019 at 9:59

2 Answers 2

1

by default django gives you {{ request.user.username }} through out your templates. So you can call it on any templates

Sign up to request clarification or add additional context in comments.

Comments

0

You aren't passing the usrnm in your post request with SUBMIT on your SecondPageSub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.