Forums

Changing HTML files

Dear Pythonanywhere team:

In my plan I currently have 3 web apps; I use 2 of them almost every day, so let’s assume I have just 2. Those 2 web apps are currently in production, and I have 2 other accounts where I test my changes before going live.

Regarding that, I have 2 questions:

  1. Is there any other way to have a separate environment? I mean, having a production server and a development server in 1 account?
  2. When I modify any HTML file on my “trazabilidapp” webapp I just have to save the file, press F5 on the live site and the change is instantly applied. But when I modify an HTML file in my second app (billpest) I have to save the file, reload the app and then I can see the changes. Is there anything I can do to make this second app behave like the first one? It is kind of annoying having to reload every time I make some small change. This behavior applies to my production environment as well as my dev environment (1 account for “trazabilidapp” and 1 account for “billpest”), so I assume is not the account, maybe I configured something wrong.

I hope I made myself clear. The second point is more important for me.

Thank you!

It looks like it is more about your browser. When you reload, do you do a hard reload that is clearing your browser cache?

I do.

I have tried with Firefox, Edge, Chrome and Opera. And the results are the same

  1. Yes, you can have as many web apps as you like in a single account and one of them can be your live one and the other your dev one.

  2. That sounds like you're serving the pages in different ways so that they are behaving differently. Check everything about the apps so that you can determine what the difference might be.

They are both using python 3.7

The wsgi.py file is identical (except for the path, obviously)

The imports for both apps in flask_app.py are similar, not identical. But nothing out of the ordinary.

Where else should I check?

Make sure that you're serving them the same - static files vs not. Check the config for both web apps. Anything else you can think of.

I found the answer! I don't know why this works, but it does.

Old code:

app = Flask(__name__)
db = SQLAlchemy(app)
app.config["DEBUG"] = True

New code:

app = Flask(__name__)
app.config["DEBUG"] = True
db = SQLAlchemy(app)

Can you explain why this works?

Thank you

That makes sense. The SQLAlchemy object will only pick up the config parameters that are present in the app object at the time that it is created, so your old code creates one with DEBUG set to the default value of False, while the new code sets it correctly, and applies the reload behaviour that you want.

That said, debug mode is less efficient than non-debug mode, so you would get a performance boost by switching it off -- though, of course, that would mean that you'd need to reload the site from the "Web" page after making any changes. Perhaps you could make it the default behaviour for dev but not for prod?