PusherBadRequest未知的Auth_Key

时间:2017-05-18 15:35:20

标签: python django real-time pusher

我正在构建此应用,以便每当我在更新视图中更新用户时,包含用户详细信息的其他视图都会显示更改通知。

我得到了PusherBadRequest未知的Auth_Key,但所有的配置都是正确的,你可以在我的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})

模板

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>

1 个答案:

答案 0 :(得分:1)

这是因为django-pusherable库不知道Pusher集群,并将您的应用配置为使用>> test: [%a/b] == [%a/b] >> change skip test/1 2 %c == %"" >> test == [%a/c] >> change next find test/1 slash "d" == %"" >> test == [%a/d] >> parse test/1 [thru slash change skip "e"] == true >> test == [%a/e] 集群。您的应用位于mt1群集上,该群集不了解您的应用。

这是django-pusherable中的一个错误,我们会及时修复它。当我们发布修复程序时,我会回复您。 (我为Pusher工作!)