gambit2017
gambit2017

Reputation: 277

Flask - getting error when trying to config an app

I have the following directory structure:

app.py
config
    __init__.py
    settings.py
instance
    __init__.py
    settings.py

app.py looks like this:

app = Flask(__name__)

debug_toolbar = DebugToolbarExtension()
mail = Mail()
csrf = CsrfProtect()

app.config.from_object('config.settings')
app.config.from_pyfile('settings.py', silent=True)

@app.route('/')
def hello_world():
    return "hey"

debug_toolbar.init_app(app)
mail.init_app(app)
csrf.init_app(app)

app.run(port=8000)

and my settings.py file in both folders looks like this:

DEBUG = False

SERVER_NAME = 'localhost:8000'
SECRET_KEY = 'insecurekeyfordev'

# Flask-Mail.
MAIL_DEFAULT_SENDER = '[email protected]'
MAIL_SERVER = 'smtp.gmail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USE_SSL = False
MAIL_USERNAME = '[email protected]'
MAIL_PASSWORD = 'awesomepassword'

# Celery.
CELERY_BROKER_URL = 'redis://:devpassword@redis:6379/0'
CELERY_RESULT_BACKEND = 'redis://:devpassword@redis:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_REDIS_MAX_CONNECTIONS = 5

If i remove the 2 lines in app.py that take care of the configuration, my app works fine and i get hey when i try to access 127.0.0.1:8000.

If i keep those lines in the file, i get a 404 error when i try to access that address.

What could be the problem?

Upvotes: 0

Views: 121

Answers (1)

plaes
plaes

Reputation: 32716

You are setting the SERVER_NAME to localhost:8000, but trying to access it actually via 127.0.0.1.

Therefore comment out the SERVER_NAME variable in your configuration.

Upvotes: 1

Related Questions