相关疑难解决方法(0)

通知面板类似于stackoverflow

还记得显示在页面顶部的小div来通知我们的事情(比如新的徽章)吗?

我也希望实现类似的东西,并且正在寻找一些最佳实践或模式.

我的网站也是一个ASP.NET MVC应用程序.理想情况下,答案将包括像"把细节在母版页"和"做这样的控制器".

为了避免您不必自己查看,这是我在未在stackoverflow登录时收到的欢迎消息中看到的代码.

<div class="notify" style="">
  <span>
    First time at Stack Overflow? Check out the
    <a href="/messages/mark-as-read?returnurl=%2ffaq">FAQ</a>!
  </span>
  <a class="close-notify" onclick="notify.close(true)" title="dismiss this notification">×</a>
</div>

<script type="text/javascript">

  $().ready(function() {
    notify.show();
  });

</script>
Run Code Online (Sandbox Code Playgroud)

我想补充一点,我完全理解这一点,也理解jquery的参与.我只是对将代码放入标记以及何时("谁"以及ASP.NET MVC应用程序中的哪些实体)感兴趣.

谢谢!

asp.net-mvc

26
推荐指数
2
解决办法
3418
查看次数

新的聊天消息通知Django频道

我已Django Channels 2.1.2按照教程在Django应用程序中进行了设置,现在需要为新消息设置通知系统。我想以最简单的方式做到这一点。

我可以通过浏览器推送通知来执行此操作,但是我不想那样做。我希望它像Stack Overflow,其中有一个红色的数字代表新消息的实例。

这里的一个答案说

对于通知,您仅需要两个模型:UserNotification。在连接时,将范围设置为当前经过身份验证的用户。post_saveNotification模型上设置一个 信号,以触​​发使用方方法向通知对象的用户发送消息。–

我正在竭尽全力去寻找什么样的样子,我已经有了一个User模型,但是没有Notification人。

聊天仅在2个用户之间进行,它不是聊天室,而是更多的聊天线程。2个html模板是inbox.htmlthread.html

感谢任何帮助!

我的Django频道代码如下!

users.py

class ChatConsumer(AsyncConsumer):
    async def websocket_connect(self, event):
        print('connected', event)

        other_user = self.scope['url_route']['kwargs']['username']
        me = self.scope['user']
        #print(other_user, me)
        thread_obj = await self.get_thread(me, other_user)
        self.thread_obj = thread_obj
        chat_room = f"thread_{thread_obj.id}"
        self.chat_room = chat_room
        # below creates the chatroom
        await self.channel_layer.group_add(
            chat_room,
            self.channel_name
        )

        await self.send({
            "type": "websocket.accept"
        })

    async def websocket_receive(self, event):
        # …
Run Code Online (Sandbox Code Playgroud)

python django django-models django-views django-channels

9
推荐指数
1
解决办法
1576
查看次数