Trouble with POST requests using FLASK

I am building a web scraper in python and am using flask to later deploy it as a web app and BULMA to easily style up my page as an alternative to Bootstrap.

Even after having read the documentation on how to build flask forms and some guides such as this one (Working with forms in Flask | Learning Flask Ep. 7) and watching some tutorials I am having some trouble handling the post request method though. The web page (index.html) page is rendering correctly every time I start the server, and I am getting a “GET / HTTP1.1” 200 response from the server.

However when I try entering some data in the input fields and press the “scrape” button, I am not seeing
“POST / HTTP/1.1” 200" show up in the terminal.

I am sure that the error is somewhere silly but i cannot for the life of me figure out what I did wrong. Any help would be greatly appreciated.
Here is the code:

(main.py file):

from flask import Flask, render_template, request, redirect, url_for
from bs4 import BeautifulSoup
import requests
import lxml

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def get_dev_jobs():
	if request.method == "POST":
		link = request.form["link"]
		tag = request.form["tag"]
		return render_template("result.html")
	return render_template("index.html")

if __name__ == "__main_":
	app.run(debug=True, port=8000)

index.html fie:


<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>!</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css">
  </head>

  <body>
  <div class="block">
<section class="hero is-link">
  <div class="hero-body">
    <p class="title">
    A Python-based Web Scraper
    </p>
  </div>
</section>
      </div>

<div class="block">
<div class="container is-fluid">
    <form action="#" method="POST">
  <div class="form-group">
    <label> Enter the URL link you wish to scrape:</label>
    <input class="input is-link" type="text" placeholder="URL link" name="link">
  </div>
    </form>
</div>
</div>


  <div class="container is-fluid">
      <div class="block">
      <form action="#" method="POST">
  <div class="form-group">
    <label>Enter the HTML tag you wish to scrape: </label>
      <input class="input is-normal" type="text" placeholder="HTML TAG" name="tag">
  </div>
      </form>
  </div>
  <button type="scrape" class="button is-dark" class="button is-large">Scrape!</button>
  </div>
  </body>
</html>

hello.
the form is not being submitted because submit button is not in that form.
all inputs and submit button should be in one <form> tag, and button type should be submit.

<form action="#" method="POST">
  <div class="form-group">
    <label> Enter the URL link you wish to scrape:</label>
    <input class="input is-link" type="text" placeholder="URL link" name="link">
  </div>
  <div class="form-group">
    <label>Enter the HTML tag you wish to scrape: </label>
    <input class="input is-normal" type="text" placeholder="HTML TAG" name="tag">
  </div>
  <button type="submit" class="button is-dark" class="button is-large">Scrape!</button>
</form>
1 Like

This fixed the problem, thank you so much!