Forums

How to add a second web app to the same directory?

I created a little API to calculate the speed of sound. It lives at nathanlively.pythonanywhere.com/speedOfSound/

Now I want to create another little API that will ingest a CSV file and output JSON data. Do I need to go through the entire "Add a new web app" process or can I just create another directory in nathanlively.pythonanywhere.com/ and add the flask_app.py file? I ask because I tried this already and it didn't work.

Sorry if this has been covered already. I looked through the documentation and searched through the forum and didn't see this specific question, yet, but I'm also a novice so I just may have not understood. Thanks!

No, you do not need to create a new app, just add a new endpoint with separate routing to your existing one.

So, if you have some function like, for example:

@app.route('/speedOfSound/')
def something:
    ...

add a new one:

@app.route('/swallow_scv/')
def something_else:
    ...

Ah, ok. Interesting. So I don't even need to create the new /swallow_scv/ directory. I just reference it in the original flask_app.py file?

No, you do not need to create a file for every one of your views. The code in the view determines what the view returns.

Thanks!