How to Deploy D3 in Heroku (Django App)? - django

I'm trying to create a data visualization for yahoo finances, which I've successfully done locally using Django 1.9.2. It scrapes yahoo finances and then uses D3 to create bubble charts with tooltips.
However, the bubbles don't show up:
https://pure-woodland-72284.herokuapp.com/
This is what appears in Heroku logs.
Heroku Log Error Messages
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_swagger',
'mysite'
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(os.path.dirname(__file__), 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
REST_FRAMEWORK={
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
]
}
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',
)

Your console have the following errors:
Mixed Content: The page at 'https://pure-woodland-72284.herokuapp.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://fonts.googleapis.com/css?family=Lobster+Two:400,700italic'. This request has been blocked; the content must be served over HTTPS.
Hence you are getting 'Uncaught ReferenceError: $ is not defined' error since you did not really imported your libraries
So I'm guessing that you have imported your scripts (jquery,d3.tip,cssfonts) from their cdn and used http while importing. Try importing them with https and see if that solves your problem

Related

Django Rest Framework and Heroku - Error 401

I just deployed my website on Heroku, an integral part of the functionality of the site is to receive post requests from another website of mine. I'm using DRF's TokenAuthentication for my authentication. In my local environment everything works perfectly, but the same cannot be said for the live website. Whenever I send a POST request I receive a 401 error, the new token is added to the request's header and the data is exactly the same as the data used in the local environment. Any help would be gladly appreciated.
views.py
class PetCreateView(CreateAPIView):
serializer_class = PetSerializer
permission_classes = [IsAuthenticated, ]
def perform_create(self, serializer):
if Breed.objects.filter(user_id=self.request.POST.get('breed_name', None)).exists():
pass
else:
Breed.objects.create( breed_name=self.request.POST.get('breed_name', None),
size=self.request.POST.get('size', None),
temperament=self.request.POST.get('temperament', None),
energy=self.request.POST.get('energy', None),
hypoallergenic=self.request.POST.get('hypoallergenic', None))
breed = Breed.objects.get(breed_name=self.request.POST.get('breed_name', None))
# Assigns a groomer the created Pet
groomer = assign_groomer(breed)
serializer.save(groomer=groomer, breed=breed)
SpaReport.objects.create(breed=breed, groomer=groomer)
settings.py
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'bootstrap3',
'captcha',
'django_celery_beat',
'django_celery_results',
'mathfilters',
'storages',
'account',
'sales',
'scrty',
'analytics'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'pettracker.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR, ],
'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',
'scrty.context_processors.from_settings',
],
},
},
]
WSGI_APPLICATION = 'pettracker.wsgi.application'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}

Facebook has detected Believer isn't using a secure connection to transfer information

Well I am trying to add login and sign up with facebook functionality and when i click on login with facebook it takes me to facebook but shows an error such as
Facebook has detected Believer isn't using a secure connection to transfer information.
Until Believer updates its security settings, you won't be able to use Facebook to log into it.
I used comments for those lines which i add for social app. This code is from my project/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap3',
'accounts',
'social_django', # <--adding social app
]
AUTHENTICATION_BACKENDS = (
'social_core.backends.facebook.FacebookOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.github.GithubOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware', #<--for social app
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'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',
'social_django.context_processors.backends', # <-- Here
'social_django.context_processors.login_redirect', # <-- Here
],
},
},
]
LOGIN_REDIRECT_URL = 'test'
LOGOUT_REDIRECT_URL = 'thanks'
SOCIAL_AUTH_FACEBOOK_KEY = '1289678764728890' # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = '1c2a66c9c8116e4e2d97cb059db5d6a9' # App Secret

Django - linkedIn API - client error(410) - HTTPError at /complete/linkedin-oauth2/

I need to get some information from LinkedIn profile of a user to fill existing fields of my application form. So I am using LinkedIn API(I have created app in linkedin and stand with client_Key, client_Secret,r_liteprofile and r_emailaddress permissions). Now it is prompting me to sign-in with linkedIn and asking for "Allow" permission(All OK till this prompt) but In the next page I'm getting below error instead of showing json file with user information.
"""
HTTPError at /complete/linkedin-oauth2/
410 Client Error: Gone for url: https://api.linkedin.com/v1/people/~:(first-name,id,last-name)?oauth2_access_token=AQVpVZCnhj2oLkzUvQytDU89kJUMm5yEIadV0BZMid3WVqPSVdOiJIePGIH7ZL7i3M5gppOlbUqpS68rDaaio56Y-nkC3Njpvf91v8WUPxQ8t-3uqJRzCC_MdrKUpntLalp24Eo2BMjpYIKeHGdxjFIlaMt9tszkIVHpPcZA2-dgbqOBrvt9-QE4P91bTXqBBkrtHEXg9F560OvltnQDgc0U1xwO-5yOT5LjlqAtvDJ_gMf3G8rZ9cdkayq4aP1CO-ljglGqlJb4uxorPRg7qPqqkNaAmQjXploM0KVQ6pK7nidP4zC2l7WW1aqg38GRDe8AM8jzaiIkg-SX3JfCJA28fT9H8A&format=json
"""
Below is my code, Did I miss anything....I'm newbie to Django Please help me to fix it??
I have tried to get exact access token format like{access token:XXXXX,expires in:XXX} with url https://www.linkedin.com/oauth/v2/accessToken?grant_type=client_credentials&client_id=[my_client_ID]&client_secret=[my_client_secret] I got below response.
{"error":"access_denied","error_description":"This application is not allowed to create application tokens"}
How can I achieve it??
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'bootstrap4',
'social_django',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware',
]
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',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'social.backends.linkedin.LinkedinOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'my_client_ID'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'my_client_secret'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE = ['r_liteprofile']
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = ['r_emailaddress']
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [('id', 'id'),
('firstName', 'first_name'),
('lastName', 'last_name'),
('emailAddress', 'email_address')]
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/home/'
SOCIAL_AUTH_LOGIN_URL = '/'
```[the error I'm getting][1]
[1]: https://i.stack.imgur.com/ECS3N.png

Integrate django auth with Nodejs passport authentication?

I have django app that is using postgresql as a backend. It have different authentication method and this app running on server A .
setting.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'login',
'reports',
)
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 = 'reporting.urls'
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_PATH],
'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 = 'reporting.wsgi.application'
and my second application is on Nodejs with backend mongoDB and authentication method is passport-local. It is running on server B
primary app is Django.
Now I want If Login from django app and click to link that directly go to Nodejs app without login.
Or any other method for login in both application with single authentication.

Unable to use Django-allauth with my Django project

Being a Django newbie, facing problem in using Django-allauth with my project. I installed the Django-allauth package in the virtualenv of my project successfully and also have made the relevant changes in the settings.py file to configure the same with my project.
I also checked the "requirements.txt" file and it has a line as "django-allauth==0.23.0". But as soon I tried to run the 'python manage.py migrate' command, I got an ImportError saying: No module named allauth.
Below is my code for settings.py:
Settings.py
...
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google',
'myapp_v1',
)
SITE_ID = 1
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder'
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
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 = 'myapp.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',
'django.template.context_processors.request',
],
},
},
]
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
...
Please let me know if I am missing something over here.
Since our discussion in comments identifies the problem, I'll post my answer.
I'd suggest a few ways that you can use.
Uninstall one of the python versions as you do not actually need two python running. Alternatively, remove one of the python paths from your environment variables so that both CLI and your project use same versions.
Use Pycharm, an IDE which will let you use specific python version through its interface and will allow you to install packages for the version you have selected.
or
Follow this thread on stackoverflow. Which is a similar question as you asked in your last comment.