hagsteel / swampdragon

swampdragon
Other
556 stars 73 forks source link

0.4.2.2 issues w/ tutorial psutil #193

Open ghost opened 8 years ago

ghost commented 8 years ago

Ok, tried for quite a while today to setup the demo using psutil. Keep getting an error on the browser side as follows:

TypeError: window.swampdragon_settings is undefined 
ReferenceError: swampdragon is not defined

Tried to hunt this down but having a hardtime finding where the issues are coming from. Pycharm is telling me that swampdragon_host is unresolved in swampdragon.js.

function getHost() {
    var host = window.swampdragon_host,
        endpoint = window.swampdragon_settings.endpoint;

    if (endpoint.indexOf('/') != 0) {
        endpoint = '/' + endpoint
    }

    host = host + endpoint;
    return host;
}

Any ideas?

MBrouns commented 8 years ago

Do you have the settings.js file included in your page?

ghost commented 8 years ago

I followed this tutorial. Did not see a settings.js included anywhere in this.

Disclaimer: I am new to this so I could be over looking something completely, but I have followed the tutorial step by step and not having any success.

MBrouns commented 8 years ago

In the adding template part of the tutorial you see the following code in the body of the page {% swampdragon_settings %}

If you're using django templates you should make sure that that line is there. If you're using something else such as a standalone front-end app you should include a link to the settings.js file manually like such <script src="http://address_of_sd_host:9000/settings.js></script>

ghost commented 8 years ago

This is my html page. I am using django.

{% load static swampdragon_tags %}
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<h2 id="sent"></h2>
<h2 id="rcvd"></h2>
<h2 id="cpu"></h2>

<!-- SwampDragon -->
{% swampdragon_settings %}
<script type="text/javascript" src="{% static 'swampdragon/js/dist/swampdragon.min.js' %}"></script>

<!-- Monitor -->
<script type="text/javascript" src="{% static 'monitor.js' %}"></script>

</body>
</body>
</html>
ghost commented 8 years ago

ok also saw elsewhere here that I needed to runmanage.py runsd Did that now I get these errors.


GET  http://127.0.0.1:8000/static/monitor.js  [HTTP/1.0 404 NOT FOUND 17ms]
TypeError: window.swampDragons is undefined
ghost commented 8 years ago

Also here is my settings.py file

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&@u#p(!j5ri51f#&flm3q4$13byl!(j1!qezvsxvh#e5-74%3$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'swampdragon',
    'monitor'
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'servermon.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'servermon.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

# SwampDragon settings
SWAMP_DRAGON_CONNECTION = ('swampdragon.connections.sockjs_connection.DjangoSubscriberConnection', '/data')
DRAGON_URL = 'http://localhost:9999/'
ghost commented 8 years ago

Welp solved my issue. Seems to be a combination of the following.

  1. Needed to tun manage.py runsd
  2. Needed to change some configurations regarding static files in settings.py

replaced

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

with

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = ( os.path.join('static'), )