Forums

relative URLs go to my username.pythonanywhere.com not to my domain

I've got URL redirect set up with my DNS so that if i go to the domain, it redirects to the flask app on python anywhere as i expect. The domain name is maintained in the browser

i then have some buttons which use javascript and 'window.location.assign("/relative/url") which is then intercepted using flask routes to deliver a template. This maintains the domain name in the browser still

but if I use a hyperlink (eg "href=/relative/url") within a page rendered from a template, the relative URL is the same but it sends me to "username.pythonanywhere.com/relative/url"

at first i thought this was perhaps because these links open in a new tab, but hovering over them shows that they resolve to the pythonanywhere domain name, not my own one, before you click on them

help! I'm confused. How do I get these links to maintain the domain name? do I need them to go through a route in my app?

The URL redirect is probably just including your web site in an iframe so, as far as the actual page is concerned, the site is still at username.pythonanywhere.com, so that is where URLs that do not specify a host will go.

yeah it's returning an iframe when i am at the proper domain name, and its returning the full source on any of the links that go to the pythonanywhere url

what's the best solution for this? I want all my links to show the proper domain name but i'm not sure how to go about that

If you want the links to show a different domain to the one that they are being served from, you will need to include the domain in the link href.

i tried giving the full link inside the anchor tag but it does this: username.pythonanywhere.com/www.domainname.com/resource

hmm try https://www.domainname.com

ok so that works with the http prefix, but my browser can't find an IP address any time anything is added onto the end of that URL (www.domain.com/resource/)

it reports DNS_PROBE_FINISHED_NXDOMAIN

does this perhaps mean my DNS is not redirecting anything other than the bare www.domainname.com to the python anywhere flask app?

It sounds more like you're not specifying the URLs correctly. If you view the source of your page, what is the exact URL that is causing the problem (including any "http://" or "https://" at the start)?

OK I have sort-of sorted it. I at least get pointed back to my flask app with the URLs now... though my flask app doesn't respond correctly but i'll sort that.

is there a way to stop javascript alerts from mentioning that they come from python anywhere, and instead use the domain name?

No, I don't think so -- I believe it's a security feature so that people know where embedded popups are really coming from.

ok thanks, i'll probably look into making a custom popup instead

thanks for the help everyone