I've made a Python Flask app and I have some questions about the structure of the main module (equivalent of index.py).

Here is what it looks like:

from flask import Flask, render_template

import database as db    
import weather_forecast as wf
import os

app = Flask(__name__)

def home():
    return render_template('home.html',  

def contact():
    return render_template('contact.html')

#creates url using climbing area name, city id, lat, lon, and location of weather site
def weather_forecast(climbing_area, city_id, lat, lon, weather_site):

    return render_template('weather_forecast.html', 
                       historical_forecast=wf.get_historical_weather(lat, lon),
                       image_url=wf.image_choice(lat, lon, city_id))

if __name__ == '__main__':

I have three pages in my application, home, contact, and a dynamically created weather_forecast url.

Basically, when the home() function runs and renders the home page template, it runs this line: sites=db.create_site_list_sqlite() The create_site_list_sqlite() function returns a bunch of data from an SQLite database, which is used to populate some a href hyperlinks. When a user clicks on one of those links, it goes to a weather forecast page, created by the def weather_forecast() route. That same data is then used to populate the URL in the proceeding weather forecast page.

My reason for doing this is, it was the best way I could figure out to run the create_site_list_sqlite() function. I could have populated the weather_forecast url by re-running that function but it seemed redundant.

Is this good practice to run the create_site_list_sqlite() function (or any others) as few times as possible?

Also, because I needed several pieces of data from what that function returns (climbing_area, city_id, lat, lon, and weather_site), the url for a weather forecast page is rather long. I personally think its fine but is there some reason to tighten this up if possible, just as an example, here is what one of the weather forecast page URLs looks like:


Thank you for any input.

  • \$\begingroup\$ Please show your template code. \$\endgroup\$
    – Reinderien
    Jul 5, 2020 at 13:31

1 Answer 1



URL components should generally appear from "broadest to narrowest" left-to-right. I'm not totally convinced that this is currently the case - the weather site is probably "broader" than the latitude and longitude.

Is the city within a climbing area, or vice versa? If a climbing area is within (or smaller than) a city, their positions should be reversed.

How many of those parameters can be inferred from other parameters? If you only specify the city, could default coordinates be inferred? Try to omit as many optional parameters as possible from the path, and move them to query parameters.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.