I am sorry if this is a really stupid question but it feels that I am missing something when it comes to understanding how exactly the action
attribute works. Most of the tutorials I have come across run on localhost so it makes sense when you simply provide action = "dir/register.py"
as it is located on the same machine and the POST request
knows where to go.
But, when we make a live website for example lets say I make an EC2 instance, install Ubuntu and use that as the backend- I would get an IP address. I will make this static and then register with a DNS to tell the internet that my website name xyz.com is on static IP x:x:x:x
.
Now, say a user requests for the registration page, my routes will send the necessary html, css, js pages back to the browser for the users to enter details. What I don't understand is how does the browser know to send it back to the backend on submit when the action attribute specified by me is still action = "dir/register.py"
.
Does the browser automatically remember where the request came from and internally handle it by appending the necessary IP
to specify the absolute path for my script to handle registration or do I have to change the action attribute to action = "x:x:x:x/dir/register.py"
when making a live website?
EDIT 1:
Code for url that processes form data (probably):
@users.route("/register", methods = ["GET","POST"])
def register():
if current_user.is_authenticated:
return redirect(url_for('main.home'))
form = RegistrationForm()
if form.validate_on_submit():
hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
user = User(username = form.username.data, email = form.email.data, password = hashed_password)
db.session.add(user)
db.session.commit()
flash(f'Account created for {form.username.data}!', 'success')
return redirect(url_for('users.login'))
return render_template('register.html', title = 'Register', form = form)
question from:
https://stackoverflow.com/questions/65913250/how-exactly-does-the-form-action-attribute-in-html5-send-the-data-to-the-backe 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…