Ask coding questions

← Back to all posts
Why Is My Redirect Button Not Redirecting?
joecooldoo

I am making a mailing system that uses Python Flask. My template has the following HTML:

When I press the "Send" button, It doesn't redirect me anywhere. It just stays at the page it is at. What am I doing wrong?

Voters
Glitchez
joecooldoo
Comments
hotnewtop
CosmicBear

Use the form element.

Glitchez

I do not know flask however in html/js you would use form action="yourwebpage.yourending"> so maybe look into form and action

joecooldoo

@Glitchez Problem: I have custom url so the url is not fixed. It changes depending on what you put in textboxes

Glitchez

@joecooldoo you can change the url in js to make it change dynamically here is a recourse I found that I think you will find helpful
https://www.w3schools.com/jsref/dom_obj_text.asp

joecooldoo

@Glitchez I can't figure it out

Glitchez

@joecooldoo just curious do you have a lot of experience in flask, html, python, or just any back end programming, because redirecting dynamic urls is not an easy task

joecooldoo

@Glitchez Flask And Python. I'm not as good in HTML though,

Glitchez

@joecooldoo you might want consider using html/css for this since flask is a pretty crude implementation of html/python

CosmicBear

@joecooldoo can you share a repl. Also you should probably do the redirect in the back-end if you're not as familiar with javascript.

joecooldoo

@Glitchez I am using Python for a reason

Glitchez

@joecooldoo mind sharing the reason maybe I can provide some insight

joecooldoo

@Glitchez I need python because it uses the database.

Froggo-School

@joecooldoo

You may want to try:

instead of:

CosmicBear

@joecooldoo can you share the repl pls.

CosmicBear

I know how to do it. Just use a post request to get the data in the backend (request.form) and then redirect using the redirect function from flask.

joecooldoo

@CosmicBear I don't want to use POST...
Here is link to Repl: https://replit.com/@AshleyOrSomethin/SMail

Glitchez

@joecooldoo for databases, replit has databases built in and in general I would recommend integrating sql for that

Glitchez

@joecooldoo honestly I feel like you are trying to cut steak with a plastic knife. doable, but very time consuming and annoying useless considering you have a metal knife at your hand. just use js or at least sql

CosmicBear

@joecooldoo why don't you want to use POST?

joecooldoo

@CosmicBear It's just to complicated to me.

CosmicBear

@joecooldoo It would be a lot easier if you use POST. What part of it is too complicated? The flask part or just POST in general?

joecooldoo

@CosmicBear POST in general. I know nothing about it.

CosmicBear

@joecooldoo would you use POST if I explained it to you?

joecooldoo

@CosmicBear Probably.

CosmicBear

@joecooldoo So when you go to a website, you are GETting data from the server that runs that website. So imagine there is a library and you borrow a book. Now think of POSTing a comment on Replit. You are giving data to the server. GET is when you receive data (going to the website and reading comments) and POST is when you GIVE the data (when you yourself post a comment). In a form in HTML, you can fill it in and then the it PUTs the data into the server after you submit it. PUT and POST are interchangeable. You can GET a youtube video from the youtube servers and watch it or you can POST a video and PUT it in the youtube servers. When you open a website, you GET the html from the server and it is displayed to you. POST is the opposite. You PUT the data into the server.

In flask, @app.get or @app.route means that you can get HTML from that url. @app.post or @app.route(methods=["POST"]) means that that URL is for POSTing data to the Flask app only.