Forums

How to host/deploy app2 for "my own domain"?

So, I have the default flask_app on "myusername.pythonanywhere.com", which seems working well.

Now, I want to add my second web app, "app2". I understand, I could do "myusername.pythonanywhere.com/app2" with proper WSGI config mapping.

In the meantime, pythonanywhere supports "app2" to use my "own domain" as well, but my domain is already hosted by another company, do we need to transfer DNS server etc. over to pythonanywhere?

Thanks.

If you want two websites under .pythonanywhere.com, they'd need to end with yourusername.pythonanywhere.com -- that is, you can have a site that's just that, or you could have secondapp-yourusername.pythonanywhere.com, and so on. This help page has the details.

However, you can, as you say, use your own domain. We don't provide DNS servers, but almost all domain registrars do provide them as part of their service, and you can use them to create a CNAME record, which essentially tells the DNS system which servers your site is hosted on. Which company do you have your domain with right now? If you'd rather not post about it in public here, then we can move the conversation over to email at support@pythonanywhere.com.

I see, no wonder my second app is so slow...

" If you want two websites under .pythonanywhere.com, they'd need to end with yourusername.pythonanywhere.com -- that is, you can have a site that's just that, or you could have secondapp-yourusername.pythonanywhere.com, and so on. ", do you have a sample for WSGI config code for such architecture?

Thanks in advance.

You don't need to do anything special in the WSGI file for that -- just create a new website using the "Add a new web app" button on the "Web" page, then select the "Your own domain" option, and type in the domain name you would like (we're working on a better UI for that).

Ok, but upon clicking the "Add a new web app" button, the "yourusername.pythonanywhere.com" option is dimmed, leaving the only available option to "your own domain", but I want the "the second app" to be under "yourusername.pythonanywhere.com" .

The "Reload" option is no longer available. My app is decidedly slower.
(The app functionality hasn't be changed)

It looks like you already have web app under your username. What do you mean by 'The "Reload" option is no longer available.'?

Ok the "Reload" and log access are all back.

Now, question, for the WSGI config file, the current working code is as follows:

from flask_app import app as application  # noqa

but the flask_app.py and app.py are exactly the same script, so, this seems double loading, which of course is not desirable.

I tempted the following modifications to no avail:

from flask_app as application

or

import app as application

Thanks.

[edit by admin: formatting]

This code:

from flask_app import app as application  # noqa

...means "from the file flask_app.py, import the variable app, but use the name application to refer to it". So that does what you need -- app.py would not be involved.

Got it, that makes sense. I was familiar with syntax like

import an class from a separate script

from flask_app import aClass

Thanks.

Btw, my second app's error log is empty but there's an error.

There seems to be a problem with path or directory mapping for my newer app ("newerapp-myusername.pythonanywhere.com")

Backend code has a router of @app.route('/assess', methods=['POST'])

PA complained about it below (from log file):

[16/Dec/2024:21:13:38 +0000] "POST /assess HTTP/1.1" 500

UPDATE:

I just tested the entire code set under @app.route('/assess', methods=['POST']) as an independent script from PA shell, and it works.

Thanks.

P.S. I'm going to use PA as a short cut for pythonanywhere.com from now on.

Is the routing working in the app now?

nope. what I meant by the UPDATE is that the code itself has no issue but I suspect "" a problem with path or directory mapping for my newer app ("newerapp-myusername.pythonanywhere.com") "".

since the newer app has its own WSGI config file, what if we have its own directory and "templates" structure? but as a PA customer, I'm unable to make that happen.

You can point two apps to the same codebase.

Ok, thanks, I've identified the root case, not router mapping issue but db issue. Very weird, able to connect to the target sqlite3 db from the app but it complained target table not found. I use identical code to test the db and target table without any problem.

See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

haha, found the problem and fixed it! working but not 100% reliable yet.

appreciate the note, glenn, but not file not found type of problem.

What was the problem that you identified and fixed?

Two identical databases, the app was initially pointing to the wrong one. But I only created one. So, that's why initially I never think along that line. Having said that, PA is not at fault, I LOVE its service and support.

And I should say, Linux/Unix skill is very handy. I opened up a shell and ran a few command, bingo, problem found and then fixed.

Thanks! Glad to hear that you worked it out in the end :-)

😁