【问题标题】:PusherBadRequest Unknown Auth_KeyPusherBadRequest 未知 Auth_Key
【发布时间】:2017-10-18 12:36:04
【问题描述】:

我正在构建这个应用程序,以便每当我在更新视图中更新用户时,带有用户详细信息的另一个视图会显示更改通知。

我收到 PusherBadRequest Unknown 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>

【问题讨论】:

标签: python django real-time pusher


【解决方案1】:

这是因为 django-pusherable 库不知道 Pusher 集群,并将您的应用配置为使用 mt1 集群。您的应用位于 us2 集群上,该集群不知道您的应用。

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

【讨论】:

  • @Goun2 没问题,顺便说一句,我们正在修复github.com/pusher/django-pusherable/pull/10
  • 我将集群更改为 mt1,效果很好,但是更新时没有出现通知,再次感谢您花时间帮助我。
  • 我对这个 Django-Pusherable 有另一个问题。在我的应用程序中,当我打开视图而不是在我更新视图中的对象时收到通知,只能在发生操作时推送通知吗?例如更新或删除。
  • @Goun2 现在在pypi.python.org/pypi/django-pusherable上发布为0.2.0
  • @Goun2 您能否将您的问题更详细地扩展为新问题?
猜你喜欢
  • 1970-01-01
  • 2013-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-08
  • 2018-01-02
相关资源
最近更新 更多