Forums

How to redirect to a specific web2py app

I would like my domain xyz.pythonanywhere.com to redirect to xyz.pythonanywhere.com/app01

What DNS or WSGI magic is needed?

Thx George

At present xyz.pythonanywhere.com redirects to xyz.pythonanywhere.com/welcome/default/index I'd like to change the target to xyz.pythonanywhere.com/welcome/app01/index I just do not understand where the welcome app has been selected

George

correction The goal is to target the app01 web2py application instead of the welcome web2py app. So, xyz.pythoneanywhere.com/app01/default/index (not xyz.pythonanywhere.com/welcome/app01/index )

George

You need to configure that routing inside your web app configuration. It's not a DNS thing.

Thank you, but I need some detail. I have one app on PA which is web2py associated with xyz.pythonanywhere.com. The web2py has 4 sites: admin, welcome, examples and app01. When I put xyz.pythonanywhere.com into the browser I get routed to xyz.pythonanywhere/welcome/default/index. My question is what table/config/code routed me to that location in the web2py site? This would appear to be what I need to modify to end up at /app01/default/index. Thank you for your patience. George

Have you checked the docs?

I am no expert and I set this up some time ago but this is working for me :-

  1. In your PythonAnywhere Dashboard tab go to Files and then to the routes.py file in the web2py folder e.g /home/xyz/web2py/routes.py

  2. Edit routes.py to change the line "default_application = 'init' # ordinarily set in base routes.py" to "default_application = 'app01' # changed etc ..."

  3. Hopefully this will now route you to /app01/default/index

  4. I also seem to have a line in routes_in =( saying " ('/$c/$f', '/xxx/$c/$f'), # get rid of /???" where xxx would be your app01 but I don't know if this is necessary.

Well, yes, I did check the docs. Found them confusing. That's why I came to the forum.

Per appgov's suggestion I located the "default_application = 'init'" line in web2py/examples/routes.patterns.example.py. I copied it and made the edit. But where does it go? If I put it into the web2py directory the app faults with "ModuleNotFoundError: No module named 'fileutils'".

Putting the routes.py into web2py/applications or web2py/applications/app01 has no effect.

I have been reloading the app before each experiment. And browser cache is off.

So far the only thing that works is a symlink in web2py/applications pointing init to app01

The error I get following the docs "Url Rewrite" appears to be a python2 dependency in the fileutils package

Adding a routes.py module into the web2py directory causes the fault. Doing the experiment described in https://help.pythonanywhere.com/pages/DebuggingImportError/ I see:

python3.10 /var/www/gasilvis_pythonanywhere_com_wsgi.py Traceback (most recent call last): File "/var/www/gasilvis_pythonanywhere_com_wsgi.py", line 20, in <module> from gluon.main import wsgibase as application File "/home/gasilvis/web2py/gluon/main.py", line 113, in <module> load_routes() File "/home/gasilvis/web2py/gluon/rewrite.py", line 456, in load load(routes, appname) File "/home/gasilvis/web2py/gluon/rewrite.py", line 384, in load exec(data, symbols) File "<string>", line 23, in <module> File "/home/gasilvis/.local/lib/python3.10/site-packages/fileutils.py", line 25, in <module> import urllib2 ModuleNotFoundError: No module named 'urllib2'

urllib2 is python2, yes?

Is this a python issue or web2py (verion 2.24.1-stable+timestamp.2023.03.23.05.07.17)

The best place to get answers for web2py-specific questions is their Google group -- that's where the real experts are likely to be.