I'm writing a small application in Flask.
run.py
#!flask/bin/python from app import app app.run(debug=True, port=9001) init.py
from flask import Flask app = Flask(__name__) from app import views index.html
{% extends "base.html" %} {% block content %} <select id = "foo"> {% for item in Citydata %} <option value = {{ item.link }}> {{ item.name }} </option> {% endfor %} </select> <a href="/new">Click here</a> {% endblock %} new.html
{% extends "base.html" %} {% block content %} <p>gafgafgadfgaerwgtdfzgaergdfzgaergaergaergt</p> {% endblock %} and lastly views.py
from flask import render_template from app import app from bs4 import BeautifulSoup import urllib2 import traceback class City_Link(object): name = "" link = "" # The class "constructor" - It's actually an initializer def __init__(self, name, link): self.name = name self.link = link @app.route('/') @app.route('/index') def index(): URL = 'http://www.amis.pk/DistrictCities.aspx' City_Data = scrape(URL) return render_template("index.html", title='Home', Citydata=City_Data) @app.route('/new/<data>', methods=['GET', 'POST']) def new(data): return render_template("new.html", title='Home', link = data) def scrape(url): data = [] try: page = urllib2.urlopen(url) soup = BeautifulSoup(page.read(), "lxml") table = soup.body.find(id='TABLE1') for row in table.findAll("tr"): heads = row.findAll("a") for head in heads: data.append((City_Link(head.text.strip(), head.attrs['href']))) except: print(traceback.format_exc()) return data When i click on the "Click me" href in index.html It gives me a 404 not found on the template new.html. I dont understand why because I followed a basic tutorial. I tried changing ports and it worked. But then I tried to update the code and it broke the link again.