RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-358264

NikUvolen's questions

Martin Hope
NikUvolen
Asked: 2024-12-25 00:21:55 +0000 UTC

Django Model 类在没有明确原因的情况下不会声明

  • 5

我正在使用来自 YouTube 的视频和 websocket 创建聊天,一切都会很好,但是当我使用 websocket 编写类本身并导入模型进行连接时,会出现有关注册此模型的错误。我已经完成了所有内容,检查了 INSTALLED_APPS,并尝试在模型中的 Meta 中指示应用程序,但没有任何帮助。

问题在于模型本身在此文件中的导入,因为在其他文件中一切正常。这是日志:

Starting ASGI/Daphne version 4.1.2 development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Python313\Lib\threading.py", line 1041, in _bootstrap_inner
    self.run()
    ~~~~~~~~^^
  File "C:\Python313\Lib\threading.py", line 992, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\mixa2\Desktop\Web\env\Lib\site-packages\daphne\management\commands\runserver.py", line 153, in get_application
    return ASGIStaticFilesHandler(get_default_application())
                                  ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\mixa2\Desktop\Web\env\Lib\site-packages\daphne\management\commands\runserver.py", line 29, in get_default_application
    module = importlib.import_module(path)
  File "C:\Python313\Lib\importlib\__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\mixa2\Desktop\Web\webProject\webProject\asgi.py", line 21, in <module>
    from apps.chat import routing
  File "C:\Users\mixa2\Desktop\Web\webProject\apps\chat\routing.py", line 2, in <module>
    from .consumers import ChatroomConsumers
  File "C:\Users\mixa2\Desktop\Web\webProject\apps\chat\consumers.py", line 5, in <module>
    from .models import GroupMessage, ChatGroup
  File "C:\Users\mixa2\Desktop\Web\webProject\apps\chat\models.py", line 5, in <module>
    class ChatGroup(models.Model):
    ...<3 lines>...
            return self.group_name
  File "C:\Users\mixa2\Desktop\Web\env\Lib\site-packages\django\db\models\base.py", line 134, in __new__
    raise RuntimeError(
    ...<3 lines>...
    )
RuntimeError: Model class apps.chat.models.ChatGroup doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

这是有问题的文件本身:

import json
from channels.generic.websocket import WebsocketConsumer
from django.shortcuts import get_object_or_404

from .models import GroupMessage, ChatGroup

class ChatroomConsumers(WebsocketConsumer):
    def connect(self):
        self.user = self.scope['user']
        self.chatroom_name = self.scope['url_route']['kwargs']['chatroom_name']
        self.chatroom = get_object_or_404(ChatGroup, group_name=self.chatroom_name)
        self.accept()

    def receive(self, text_data):
        text_data_json = json.loads(text_data)
        body = text_data_json['body']

        message = GroupMessage.objects.create(
            body = body,
            author = self.user,
            group = self.chatroom
        )

好吧,模型本身:

class ChatGroup(models.Model):
    group_name = models.CharField(max_length=128, unique=True)

    def __str__(self):
        return self.group_name

好吧,从设置连接asgi

ASGI_APPLICATION = 'webProject.asgi.application'

已安装的应用程序:

INSTALLED_APPS = [
    "daphne",
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
    "crispy_bootstrap5",
    'debug_toolbar',
    "django_htmx",

    'mainMenu.apps.MainMenuConfig',
    'novella.apps.NovellaConfig',
    'authenticate.apps.AuthenticateConfig',
    'quiz.apps.QuizConfig',
    'chat.apps.ChatConfig'
]

我将非常感谢任何建议)

python
  • 1 个回答
  • 23 Views
Martin Hope
NikUvolen
Asked: 2022-10-06 13:10:07 +0000 UTC

使用表单更新页面时出现标签类错误

  • 0

我在网站上写授权部分,js代码可以正常工作,但是当带有表单的页面更新时,输入的值仍然存在,并且js没有为输入的输入添加一个类价值。我更像是一个支持者,所以我希望你戳我的鼻子,怎么了:D

正常形式状态: 在此处输入图像描述

更新错误: 在此处输入图像描述

部分html表单:

<form id="signin-form" action="" method="POST" class="form form-sign_in" value="sign_in">
    {% csrf_token %}
    <div class="form-group">
         <label for="">Username<span class="req">*</span></label>
         {{ sign_in_form.username }}
    </div>
    <div class="form-group">
         <label for="">Password<span class="req">*</span></label>
         {{ sign_in_form.password }}
    </div>
    <button class="form-button" type="submit" name="submit" value="sign_in">Sign in</button>
</form>

js代码(jquery,因为我主要是从网上拿的):

$('.form').find('input, textarea').on('keyup blur focus', function (e) {

var $this = $(this),
    label = $this.prev('label');

if (e.type === 'keyup') {
    if ($this.val() === '') {
        label.removeClass('active highlight');
    } else {
        label.addClass('active highlight');
    }
} else if (e.type === 'blur') {
    if ($this.val() === '') {
        label.removeClass('active highlight');
    } else {
        label.removeClass('highlight');
    }
} else if (e.type === 'focus') {
    if ($this.val() === '') {
        label.removeClass('highlight');
    } else if ($this.val() !== '') {
        label.addClass('highlight');
    }
}

});

$('.tab a').on('click', function (e) {

    e.preventDefault();

    $(this).parent().addClass('active');
    $(this).parent().siblings().removeClass('active');

    target = $(this).attr('href');

    $('.tab-content > div').not(target).hide();

    $(target).fadeIn(600);
});

UPD:以防万一,这是css:

label {
    position: absolute;
    transform: translateY(6px);
    color: rgba(256, 256, 256, 0.6);
    left: 13px;
    transition: all 0.25s ease;
    -webkit-backface-visibility: hidden;
    pointer-events: none;
    font-size: 22px;
}

label .req {
    margin: 2px;
    color: #1ab188;
}

label.active {
    transform: translateY(42px);
    left: 2px;
    font-size: 14px;
}
label.active .req {
    opacity: 0;
}

label.highlight {
    color: #ffffff;
}

input,
textarea {
  font-size: 22px;
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px 10px;
  background: none;
  background-image: none;
  border: 1px solid #a0b3b0;
  color: #ffffff;
  border-radius: 0;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

input:focus,
textarea:focus {
  outline: 0;
  border-color: #1ab188;
}

textarea {
  border: 2px solid #a0b3b0;
  resize: vertical;
}
javascript
  • 1 个回答
  • 10 Views
Martin Hope
NikUvolen
Asked: 2021-12-16 21:48:21 +0000 UTC

如何为用户创建单独的表?

  • 0

我正在写一份调查问卷,保存用户的问题/答案时出现问题。我不知道如何在代码中为用户创建一个单独的表(当然,除非他还有一个表)以便代码可以使用它。我将非常感谢您的解释。

以下是此类表的一些示例字段:

class UserTable(peewee.Model):
    """База данных пользователя"""

    id = peewee.IntegerField(unique=True)
    # вопрос 1
    q1 = peewee.CharField(null=True)
    # вопрос 2
    q2 = peewee.CharField(null=True)
    # вопрос 3
    q3 = peewee.CharField(null=True)
    # вопрос 4
    q4 = peewee.CharField(null=True)

    class Meta:
        database = database
python
  • 1 个回答
  • 10 Views
Martin Hope
NikUvolen
Asked: 2020-09-26 22:35:16 +0000 UTC

如何制作字典来初始化精灵?

  • 1

如何重写和使用这个GetSprite()pod Dictionary<ItemType, Sprite>,以免为每个精灵使用单独的字段:

public Sprite GetSprite()
{
    switch (itemType)
    {
         default:
         case ItemType.Apple:
             return ItemAssets.Instance.AppleSprite;
         case ItemType.Bacon:
             return ItemAssets.Instance.BaconSprite;
         case ItemType.Bread:;
             return ItemAssets.Instance.BreadSprite;
         case ItemType.Fish:
             return ItemAssets.Instance.FishSprite;
         case ItemType.Steak:
             return ItemAssets.Instance.SteakSprite;
         case ItemType.Onion:
             return ItemAssets.Instance.OnionSprite;
    }
}

这个类也有精灵:

public class ItemAssets : MonoBehaviour
{
    public static ItemAssets Instance { get; private set; }

    private void Awake()
    {   
         Instance = this;
    }

    public Transform pfItemWorld;

    public Sprite AppleSprite;
    public Sprite BaconSprite;
    public Sprite BreadSprite;
    public Sprite FishSprite;
    public Sprite SteakSprite;
    public Sprite OnionSprite;

}
c#
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5