I'm building this app so that whenever I update an user in the update view, The other view with user's detail displays a change notification.
I'm getting PusherBadRequest Unknown Auth_Key, But all the configs are right as you can see in my settings.py.
Settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
'pusherable'
]
PUSHER_APP_ID = "340365"
PUSHER_KEY = "bbc35fac8ee3918e0048"
PUSHER_SECRET = "[REDACTED]"
pusher_client = pusher.Pusher(
app_id=PUSHER_APP_ID,
key=PUSHER_KEY,
secret=PUSHER_SECRET,
cluster='us2',
ssl=True
)
Models.py
from django.db import models
class Users(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
RELATIONSHIP_STATUS = (
('Single', 'solteiro'),
('Engaged', 'engaged'),
)
name = models.CharField(max_length=200)
sex = models.CharField(max_length=1, choices=GENDER_CHOICES)
Birth_Date = models.DateTimeField('Data de Nascimento')
Relationship_Status = models.CharField(max_length=20, choices= RELATIONSHIP_STATUS)
def __str__(self):
return self.name
Views.py
from django.shortcuts import render
from django.urls import reverse
from django.views import generic
from.models import Users
from .forms import UpdateUser
from pusherable.mixins import PusherDetailMixin, PusherUpdateMixin
class User(PusherDetailMixin, generic.DetailView):
model = Users
template_name = "Users.html"
class UsersUpdate(PusherUpdateMixin, generic.UpdateView):
model = Users
form_class = UpdateUsers
template_name = "UpdateUsers.html"
def get_success_url(self):
return reverse('users', kwargs={'pk': self.object.pk})
Templates
Users.html
{% load pusherable_tags %}
{% pusherable_script %}
{% pusherable_subscribe 'update' object %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function pusherable_notify(event, data) {
alert(data.user + "has begun to " + event + " " + data.model);
}
</script>
</head>
<body>
Name: {{ object.name }} <br>
Sex: {{ object.sex }} <br>
Relationship: {{ object.Relationship_Status }}
</body>
</html>
UpdateUsers.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
</body>
</html>