-2

I am using a non-custom domain at pythonanywhere.com

Specifically to access my non-custom domain myusername.pythonanywhere.com I use the URL https://myusername.pythonanywhere.com which has the HTTPS certificate provided by pythonanywhere.com by default.

To force the use of HTTPS to any user who accesses my non-custom domain myusername.pythonanywhere.com using HTTPS, that is, https://myusername.pythonanywhere.com, it is necessary for the user to enter the username and password that enable force HTTPS to access to my non-custom domain.

In case the credentials for HTTPS are entered correctly the user can access the non-custom domain using https://myusername.pythonanywhere.com

In the event that the HTTPS credentials entered are not correct, I want to redirect the user to a customized landing page. Specifically, if the HTTPS credentials are not validated then the user will be directed to a more personalized landing page (unauthorized_https.html) instead of receiving the “Unauthorized” message that is sent by pythonanywhere.com

My question is:

How can I implement a landing page for my non-custom domain using a HTTPS certificate provided by pythonanywhere.com?

Any help will be greatly appreciated

Thanks,

Ramiro
  • 369
  • 3
  • 14

2 Answers2

1

I would always recommend enforcing HTTPS on your website. Also, it is not possible to change between HTTPS and HTTP when you enforced it with pythonanywhere.

It is pretty simple to include a redirect, when a user is not submitting the correct credentials:

@app.route("/",  methods=['GET', 'POST'])
def index():
    if current_user.is_authenticated:

        greetings = f'Hello {current_user.email} !'

    else:
        greetings = 'Hello, please login'

    return render_template("landing.html", greetings=greetings)

@app.route("/login", methods=['GET', 'POST'])
@auth_required()
def home():
    if current_user.is_authenticated:

        greetings = f'Hello {current_user.email} !'
        return render_template("home.html", greetings=greetings)

    else:
        return redirect("/", code=302)


@app.route('/logout', methods=['GET', 'POST'])
@auth_required()
def logout():
    logout_user()

    return redirect("/", code=302)

See the repo here: https://github.com/AntonioBlago/Webpage_Tutorial_3/

0

If you want custom login behaviour in your app, you will need to implement that yourself. The documentation for the framework you're using will usually include details of how to implement logins.

Glenn
  • 7,262
  • 1
  • 17
  • 23