Update: Thank you for updating your question so that you have already tried! I have a few more ideas on what causes the problem.
Let's continue to look at HTML and try to understand the technologies that your program is built on top of. In the server-side login.html file, note the following lines:
{% from "_formhelper.html" import render_field %} {{ login_form.hidden_tag() }} {{ render_field(login_form.email, placeholder="Your Email", class="form-item__full", type="email") }} {{ render_field(login_form.password, placeholder="Your Password", class="form-item__full") }}
This is not HTML and is probably handled by the server to generate HTML code and serve the client. The line containing login_form.hidden_tag() looks interesting, so I would recommend loading this page in your browser and checking the HTML code served by the client. Unfortunately, I have not used Flask before, so I cannot give any direct help.
However, my advice is to continue working on how Flask and HTML Form work. The best part is in Python: you have access to the source code of the libraries, which allows you to figure out how they work so that you can learn how to use them and fix errors in your application that uses them.
Sorry, I canβt give you more direct help, good luck!
Take a look at login.html. When you submit a form, how does the entry route to view.py know which form was submitted? If you know HTML forms, the <input> elements embedded in the form are used to send data to your server / application in this case.
Return to login.html, pay attention to the following two lines:
... <h3>Log In To Your Account</h3> <input type="hidden" name="login_form"> ... <h3>Create a New Account</h3> <form action="" method="post"> <input type="hidden" name="signup_form"> ...
These are <input> elements of type "hidden", so they will not be displayed with the names "login_form" and "signup_form", which are included in the data that the form submits.
Now on the entry path to view.py you will see two lines:
#login form if 'login_form' in request.form and login_form.validate():
Those test to see if the phrase "login_form" or "signup_form" is in the request.form list. Let's get back to your unit test now:
response = tester.post( '/login', data = dict(username=" test@gmail.com ", password="test"), follow_redirects=True )
Pay attention to the data that you pass in the dict , this simulates the form data, so you should probably include either "login_form" or "signup_form" to correctly simulate the behavior of the HTML form.
If you are not familiar with HTML forms and HTTP messages, I would suggest looking for some tutorials or just reading the documentation on MDN or elsewhere. When creating software on top of technology (like HTTP and HTML) it may be useful to understand how these technologies work when running bugs in your own software.
Hope this helps, let me know if I can clarify anything!