6

I made the following file yesterday.

# import flask
from flask import Flask
from flask import render_template
from flask import request

app = Flask(__name__)

# create url & function mapping for root or /
@app.route('/')
def index():
    return "Hello from Flask"

# create another mapping name /hello
@app.route('/hello')
def hello():
    myName = "kayak"
    return "Hello again !!" + myName

# create mapping for /myprofile
@app.route('/myprofile')
def showmyprofile():
    return render_template('myprofile.html')

# create mapping for /myprofile
@app.route('/addprofileform')
def addprofileform():
    return render_template('myprofileform.html')

# create a mapping for /addprofile
@app.route('/addprofile')
def addprofile():
    myname = request.args.get('myname')
    state_of_residence = request.args.get('state_of_residence')
    return render_template('myprofile.html', html_page_name=myname,
    html_page_state_of_residence=state_of_residence)

if __name__== '__main__':
    app.run()

Then I made the following file today.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'This is the homepage'

if __name__ == "__main__":
    app.run(debug=True)

I thought

app.run(debug=True)

would work to clear the old data, but I doesn't and http://127.0.0.1:5000/ page keeps showing "Hello from Flask".

How do I fix this?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
kayak
  • 440
  • 3
  • 7
  • 19
  • 4
    "Clear old data"? If your old program is still bound to the port, no new program can start on that port. – Charles Duffy May 21 '17 at 21:02
  • 3
    how do you run the python files ? if through your IDE, make sure that IDE is configured to run the one you want. – Shady Atef May 21 '17 at 21:03
  • Possible duplicate of [Auto reloading python Flask app upon code changes](http://stackoverflow.com/questions/16344756/auto-reloading-python-flask-app-upon-code-changes) – JP Ventura May 21 '17 at 21:04
  • 1
    I tried to stop running the old program by clicking "stop" button, but it didn't work. – kayak May 21 '17 at 21:04
  • I'm using PyCharm. – kayak May 21 '17 at 21:05
  • 1
    Stop all running process from pycharm, then go and check your run/debug configuration in Pycharm.. They have a great [documentation](https://www.jetbrains.com/help/pycharm/2017.1/creating-and-editing-run-debug-configurations.html) on this – Shady Atef May 21 '17 at 21:07
  • I just restarted my computer and now the page has been refreshed. I still don't understand how to fix the problem but now I know at least I have an option to close everything and restart... thank you. – kayak May 21 '17 at 21:32
  • Hi you could use a diffrent port `if __name__ == '__main__': port = 8000 #the custom port you want app.run(host='0.0.0.0', port=port)` this should start a new application in a diffrent port for eg.http://127.0.0.1:8000 insttead of http://127.0.0.1:5000 – AutoTester213 May 22 '17 at 11:23
  • @kayak Did u find a solution to this? I'm using spyder IDE to run and chrome to see the output. I'm getting the old application's output even after reopening the browser. – Anne Apr 10 '19 at 20:32
  • I am running into similar issues, and I have figured out that this is a problem of flask caching your page. Read [this post](https://arusahni.net/blog/2014/03/flask-nocache.html) for instance. – Antoine Apr 29 '19 at 15:29

3 Answers3

1

Just clear the cache in your browser and try running it again.

Here's how to clear your cache in some browsers:

Firefix->https://support.mozilla.org/en-US/kb/how-clear-firefox-cache Chrome->https://support.google.com/accounts/answer/32050?co=GENIE.Platform%3DDesktop&hl=en

Golovkin
  • 33
  • 7
0

You can export the FLASK_ENV environment variable and set it to development before running the server

export FLASK_ENV=development

flask run

This worked for me.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
0

Running the program in incognito tab will not cause this error. No need to clear caches also. See https://support.google.com/chrome/answer/95464?co=GENIE.Platform%3DAndroid&hl=en