2015-07-28 10 views
6

Von dem, was ich verstehe, ALLOWED_HOSTS überprüft, wenn DEBUG=False zu verhindern, dass ein Angreifer ihre eigene Domäne auf Ihre Website zeigen.Wird ALLOWED_HOSTS auf Heroku benötigt?

Es sieht aus wie Heroku Custom Domains das gleiche tun.

Anstatt also ein erforderliches ALLOWED_HOSTS Variable in Ihrem app.json für die Heroku Button die Zugabe (da es überflüssig fühlt und ist fehleranfällig, wenn Sie in Eile sind), können Sie einstellen, ALLOWED_HOSTS = ['*'] und erlauben Heroku die Anfragen zu überprüfen kommen Wo sollten sie stattdessen?

+0

Verwandte http://stackoverflow.com/questions/16218446/why-does-setting-debug -to-false-in-django-einstellungen-stop-app-von-loading-in-devl –

Antwort

10

Das ist genau das, was Sie tun sollen, pro Getting Started with Django on Heroku:

settings.py

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

# Honor the 'X-Forwarded-Proto' header for request.is_secure() 
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

# Allow all host headers 
ALLOWED_HOSTS = ['*'] 

# Static asset configuration 
import os 
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
STATIC_ROOT = 'staticfiles' 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
) 
+0

Oh schön! Alle Tutorials, die ich gelesen habe, haben Sie auf 'yourapp.herokuapp.com' gesetzt. Ich denke, ich hätte stattdessen direkt zu den Docs gehen sollen. Vielen Dank! – Joe