Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Project can't force Google Appengine to redirect to https

Using sample Django Projects and my Django Rest Framework project, I can deploy to app engine without issue.

I can access the site via both https://myappnamehere.appspot.com and the http:// version as well.

However, I'm seemingly unable to force it to only allow HTTPS.

Attempt 1: In my Django settings, I try to set :

SECURE_SSL_REDIRECT = True

This ends with my project no longer showing up on app engine, with AppEngine reporting that I should try again in 30 minutes

Attempt 2: In app.yaml, I follow the advice from here and other stack overflow threads by adding this:

handlers:
- url: /*
  script: myapplication.wsgi.application

This also ended up with the routing seemingly messed up, and all my URLs no longer routed thru the django router as expected.

What is inside the wsgi: import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapplication.settings.settings")
application = get_wsgi_application()

Attempt 3: Sorry, I forgot to mention I tried it with secure always, and it ends up with my site being unable to load again as well.

handlers:
- url: /*
  script: myapplication.wsgi.application
  secure: always
like image 992
ozhou Avatar asked Jun 05 '26 03:06

ozhou


1 Answers

Just add a secure parameter to the app.yaml file.

handlers:
- url: /*
  script: anyfile.py
  secure: always

See Configuring Secure URLs in app.yaml

like image 155
Bravin Balasubramaniam Avatar answered Jun 06 '26 16:06

Bravin Balasubramaniam