Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting App to Run
#1
I have been doing an online Python Tutorial at https://www.youtube.com/watch?v=B9nFMZIYQl0 at about [5:32:59 / 11:34:48]. I am trying to get the following file, script.py to run an app that will show up in Firefox. But I can't get it to show up in my Firefox Web Browser. Apparently there is a Server for the App involved, which from the software the tutor is using is <<cmd> + <enter>>, and seems to be using a web page editor called "replit", however that links to a server. It is possible that the tutor is using Flask to acheive all this. What do I need to do to get my browser to open and run the App, to show me something graphical, locally without replit to my 127.0.0.1, for example? As a beginner, what needs to be done, locally on my own PC, step by step?

import script
from script import home_page, app, show, db

database = {'number': 0}

@app.rounte('/')
def home():
     return show('home_page')

@app.rounte('/increment')
def increment():
database['number']
return 'increment'

app.run(host='0.0.0.0', port=81)
Reply
#2
There are spelling(rounte) and indentation errors in code you post.
Here are code without need of import anything else than Flask.
Call app.run() like this,then use can use localhost http://127.0.0.1:5000.
from flask import Flask

app = Flask(__name__)
database = {'number': 0}

@app.route('/')
def home():
    return 'home_page'

@app.route('/increment')
def increment():
    database['number'] += 1
    print(database['number'])
    return str(database['number'])

app.run()
Run.
G:\div_code\hex
λ python db_flask.py
 * Serving Flask app 'db_flask'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [21/Jun/2023 12:59:32] "GET / HTTP/1.1" 200 -
1
127.0.0.1 - - [21/Jun/2023 12:59:42] "GET /increment HTTP/1.1" 200 -
2
127.0.0.1 - - [21/Jun/2023 12:59:48] "GET /increment HTTP/1.1" 200 -
3
127.0.0.1 - - [21/Jun/2023 12:59:51] "GET /increment HTTP/1.1" 200 -
So now when reload browser should see increment on server and browser.
Reply
#3
(Jun-21-2023, 10:54 AM)snippsat Wrote: There are spelling(rounte) and indentation errors in code you post.
Here are code without need of import anything else than Flask.
Call app.run() like this,then use can use localhost http://127.0.0.1:5000.
from flask import Flask

app = Flask(__name__)
database = {'number': 0}

@app.route('/')
def home():
    return 'home_page'

@app.route('/increment')
def increment():
    database['number'] += 1
    print(database['number'])
    return str(database['number'])

app.run()
Run.
G:\div_code\hex
λ python db_flask.py
 * Serving Flask app 'db_flask'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [21/Jun/2023 12:59:32] "GET / HTTP/1.1" 200 -
1
127.0.0.1 - - [21/Jun/2023 12:59:42] "GET /increment HTTP/1.1" 200 -
2
127.0.0.1 - - [21/Jun/2023 12:59:48] "GET /increment HTTP/1.1" 200 -
3
127.0.0.1 - - [21/Jun/2023 12:59:51] "GET /increment HTTP/1.1" 200 -
So now when reload browser should see increment on server and browser.
Reply
#4
How do I set up Flask on Windows 10 64 bit so that Python/Idle can access it?
Reply
#5
(Jun-22-2023, 01:11 AM)Zachary1234 Wrote: How do I set up Flask on Windows 10 64 bit so that Python/Idle can access it?
Not quite sure what you mean,any Ide/Editor can be used to show the code.
Should always use command line when run the Flask code,because of the the long running process that Ide/Editor can block.
When i run code over i use cmder it's a much better cmd.
From cmd it would be the same way as shown.
G:\div_code\hex>python db_flask.py
 * Serving Flask app 'db_flask'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment.
 Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
127.0.0.1 - - [22/Jun/2023 11:48:24] "GET / HTTP/1.1" 200 -
1
127.0.0.1 - - [22/Jun/2023 11:48:27] "GET /increment HTTP/1.1" 200 -
2
127.0.0.1 - - [22/Jun/2023 11:48:31] "GET /increment HTTP/1.1" 200 -
3
127.0.0.1 - - [22/Jun/2023 11:48:34] "GET /increment HTTP/1.1" 200 -
I use VS Code when using Flask i never(Push run button) i always run it from command line.
It will work,but have have to redirect to use Terminal for output for that to work,default output Window will not show increment.
[Image: pCZ5Qw.png]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020