FrankW
FrankW

Reputation: 99

Failure in multiple times Parameters Passing in Django (Python)

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)

Upvotes: 0

Views: 45

Answers (2)

bmons
bmons

Reputation: 3392

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

Upvotes: 1

Vsevolod Timchenko
Vsevolod Timchenko

Reputation: 756

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

Upvotes: 0

Related Questions