Question

I had setup a local django server along with celery which used to be at 127.0.0.1 (I could adjust the port when running the command python manage.py runserver <port>).

Then, I wanted to set up Sentry for my app. I followed the quickstart instructions for doing this. This is what I have modified in my sentry.conf.py

SENTRY_URL_PREFIX = 'http://sentry.localhost'
SENTRY_WEB_HOST = 'localhost'
SENTRY_WEB_PORT = 9000

ALLOWED_HOSTS = ['*']

And this is what I have modified in my settings.py

INSTALLED_APPS = (
    'sentry',
    'raven.contrib.django',
    'raven.contrib.django.raven_compat'
)

SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'

RAVEN_CONFIG = {
    'dsn' : 'http://private:public@localhost:9000/2?timeout=10',
}

from sentry.conf.server import *

I had to add the ALLOWED_HOSTS = ['*'] because otherwise python manage.py raven test would fail due to suspicious header. And I had to add from sentry.conf.sever import * because otherwise I would get errors with raven with some sentry variables not being set. After setting up Sentry, I could access it from 127.0.0.1:9000.

But, I cannot access my django app. Everytime I go to 127.0.0.1:8000, I get redirected to sentry login (which gives an internal server error after logging in as its not on port 9000). Also, looking at logs from console, I see a SuspiciousOperation: Invalid HTTP_POST header error if I don't put ALLOWED_HOSTS = ['*'] at the end of my settings.py file.

How can I run both the django app and Sentry locally on the same IP (localhost) and on different ports?

Was it helpful?

Solution

Both are Django apps so they're going to want to run on port 8000 by default. However, the runserver command accepts port as an argument, so you can pass a different port to one or the other depending on how you're running Sentry. python manage.py runserver 9000 will run on that port. You'd just need to update your Sentry settings to use port 8000. Otherwise you can pass the port to Sentry's runserver command if you're using that locally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top