Forums

multiple apps on one or sub domains

Hi, I have googled this for a few days and am not coming up with answers or even anyone with the same problem which says to me that either what I am trying to do is mundanely obvious or I am trying to do something that should not be done. I am pretty new to PA. Anyway here goes.... I currently have a test app running on my own domain on PA. I have it in my head that I want to compartmentalize functionality by creating another app, which I want to serve up urls's under my domain. So basically I want to have more than one app serving up responses to url's under my domain, or sub-domains thereof. Or in another way more than one app installed in my main project serving up responses under my domain. Is this the right approach and if so how do I do it in PA? When I try to set up a new web app I it wont let me do it with the same domain as my already set-up app so must I set it up as a sub-domain? If so what is the best way? It might clarify that one reason I want to do it like this is that I want to use the same extended user model from my main project across these two (or more) apps for Authorisation of sessions. Also I like using one app as a development fork to test stuff. Anyway, any clarification appreciated from anyone. Thanks in advance.

What web framework are you using? If you are using django, you "compartmentalise functionality" by just having multiple django apps within the same project.

In terms of doing dev, you would not be able to do it on the same webapp- imagine what happens if your dev code causes your server to error / your database to be wiped etc. You will definitely want a separate webapp for that. Also you will have to keep reloading your dev webapp to see the changes.

You can certainly setup two separate webapps- dev.mydomain.com and www.mydomain.com, and use one for dev/staging.

I am using Django. Aha! I think I may have been confusing django apps with PA web apps. Thanks for the clarification. :)

Glad we could help! You're not the first person to get confused by that -- we're considering changing our official name for the kind of apps you create on PythonAnywhere to "websites". Do you think that would have helped? (We can't call them "projects" because that's a very Django-specific thing, so it would confuse people using other web frameworks.)

Changing the name might help. Probably would help muppets like me.... Everything is called apps these days though so NOT calling it an app might confuse people. Other names spring to mind, yep websites, site-containers, not-apps, muppet-traps, biscuit-tins.... hmmm.... Biscuits.....

Mmmmm....

I have a related - non Django - question for how to solve this.

I am currently running superset as a app, by calling from superset import app as application in my pythonanywhere_com_wsgi.py file.

I want to experiment with a simple app that allows the user to upload a .csv file, run some preprocessing scripts and illustrate the results using Superset.

That means I need two apps: One running Superset and another running a simple file-uploader.

In the simplest of ways, how would this be done?

Hmm, that might be tricky. On PythonAnywhere, each app is a separate website so it needs its own hostname. Do you own a domain?

Hi giles.

Right now I have the cheap solution of just one domain here (tmo.pythonanywhere.com).

So, my guess is that I need one more?

You could use something like DispatcherMiddleware. Then you can have 2 apps, under the same domain, but with different root paths.

@glenn. Neat. This worked out of the box. Thanks!

Excellent! Glad to help.

To revive this: Can I run more than 2 apps on different subdomains by doing this?

import sys
from werkzeug.wsgi import DispatcherMiddleware

project_home = u'/home/tmo/src'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

#from superset import app as ss_app
from loader_app import app as lo_app
from bokeh_app import app as bo_app

application = DispatcherMiddleware(None, {
    '/loader_app':    lo_app,
    '/bokeh_app':     bo_app
})

My folder structure looks like this

10:24 ~/src $ tree
├── __init__.py
├── bokeh_app
   ├── __init__.py
   └── bokeh_app.py
└── loader_app
    ├── __init__.py
    ├── loader_app.py

and running my wsgi file with python3 wsgi.py works fine. However, nothing is rendering on tmo.pythonanywhere.com. The apps works fine.

Hmm, I'm a bit confused -- your WSGI code there appears to be designed to run two apps on the same subdomain -- one on http://tmo.pythonanywhere.com/loader_app and one on http://tmo.pythonanywhere.com/bokeh_app. There's nothing there to do anything related to different subdomains.

When I visit http://tmo.pythonanywhere.com/loader_app I get a "something went wrong" message, and looking at the error logs it appears that there's a problem with your imports...?

Looks like you can run multiple django apps. Is it possible to run >1 flask app on the same domain? If so, how? Thanks!

you can run one single django website as one pythonanywhere webapp. django also has a concept of apps which are put together to be one single website.

the way you run multiple django or flask apps on a single domain would probably be to have different subdomains. so ie. you could setup a www.domainname.com PythonAnywhere webapp running flask or django, and then also setup a games.domainname.com PythonAnywhere webapp running flask or django, and then also setup a chats.domainname.com webapp etc.