[Python] Flask Subdomain Routing Not Working Correctly After Deployment on Render.com

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm stuck with an issue on how to properly set up subdomains in my Flask project. Here's a simple example of the code I'm working with:

    from flask import Flask

    app = Flask(__name__)
    app.config['SERVER_NAME'] = 'buytogo.space'

    @app.route('/')
    def main_index():
    return "You are visiting the main domain"

    @app.route('/', subdomain='toothpaste')
    def product_landing_1():
    return "Welcome to the TOOTHPASTE subdomain"

    @app.route('/', subdomain='cooler')
    def product_landing_2():
    return "Welcome to the COOLER subdomain"

    @app.route('/', subdomain='<subdomain>')
    def wildcard_subdomain(subdomain):
    return f"You are visiting the subdomain: {subdomain}"

    if __name__ == '__main__':
    app.run()


    I successfully deployed this project on Render.com, and there are no errors. I purchased a domain name, added it to the project on Render, and verified it (You can see the website live at https://buytogo.space/ and https://toothpaste.buytogo.space/).

    And my project is running on https://domain-testing-server-for-landing.onrender.com.

    To set up subdomains with the provider, I added the following DNS record:

    • Type: CNAME
    • Name: toothpaste
    • Value: domain-testing-server-for-landing.onrender.com

    (Note: I didn't add the cooler domain to test how it will behave.)

    Now, I am encountering an issue:

    As you can see, the same server responses appear on both https://buytogo.space/ and https://toothpaste.buytogo.space/, but based on the code, the responses should be different depending on the subdomain.

    I would appreciate any help to resolve this issue.

    Thank you!

    Continue reading...

Compartilhe esta Página