#๐Ÿ”’ Python file is not running

21 messages ยท Page 1 of 1 (latest)

silk jewel
#

i made a simple flask project but its not responding

tulip flaxBOT
#

@silk jewel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

silk jewel
#

code:

#
from weather import get_current_weather
from waitress import serve


app = Flask(__name__)

@app.route("/")
@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/weather')
def get_weather():
    city = request.args.get('city')
    weather_data = get_current_weather('city')
    return render_template(
        "weather.html",
        title = weather_data["name"],
        status = weather_data["weather"][0]["description"].capitalize(),
        temp=f'{weather_data["main"]["temp"]:.1f}',
        feels_like=f'{weather_data["main"]["feels_like"]:.1f}'
    )

if __name__ == "__main__":
    serve(app)```
tulip flaxBOT
#

Hey @silk jewel!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
tame cobalt
#

What does your terminal show?

#

How are you running it?

silk jewel
#

PS C:\Users\GrafiX\Documents\vs code\flask> & "c:/Users/GrafiX/Documents/vs code/flask/venv/Scripts/python.exe" "c:/Users/GrafiX/Documents/vs code/flask/main.py"

#

its shows this

#

and didnt run

#

i run the file by clicking the run python file option on vs code

tame cobalt
#

Try flask run --app main

silk jewel
#

the main problem is that when i remove serve(app)
and replace it with app.run() it started to work

tame cobalt
silk jewel
tame cobalt
#

Then use waitress-serve --host 127.0.0.1 main:app

silk jewel
#

its for production development

silk jewel
tulip flaxBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.