我刚刚开始使用 Django,我刚刚修改了我的项目,因此我不使用基本用户,而是使用在我的 models.py 文件夹中定义的 AbstractUser 模型
#accounts/models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
# add additional fields in here
favourite_colour = models.CharField("Favourite Colour", max_length=100)
def __str__(self):
return self.email
Run Code Online (Sandbox Code Playgroud)
我还创建了适用于我的注册系统的创建表单
#accounts/forms.py
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from django import forms
from .models import CustomUser
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = CustomUser
fields = ('username', 'email', 'favourite_colour')
help_texts = {
'username': 'Make something unique',
'email': None,
}
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个 tkinter 应用程序,当第一个窗口(根)关闭时,它不会关闭所有内容(其他窗口)。我尝试使用Toplevel()它非常适合其他程序中的弹出窗口,但不适用于制作基础级别。
from tkinter import *
top = Toplevel(bg='red')
top.mainloop()
Run Code Online (Sandbox Code Playgroud)
我不知道这是否可能,或者我不知道是否可以更改 的Tk()属性以使其不会关闭所有其他窗口。
我是 discord.py 的新手,正在尝试制作翻译机器人。当用户对某个标志做出反应时,机器人会对其进行翻译,但该事件永远不会被调用,因此我还没有代码来翻译任何消息。我知道它没有被调用,因为程序没有打印'x'到控制台。
@client.event
async def on_reaction_add(reaction, user):
channel = reaction.message.channel
print('x')
await client.send_message(channel, '{} has added {} to the the message {}'.format(user.name, reaction.emoji, reaction.message.content))
await client.process_commands(reaction.message)
Run Code Online (Sandbox Code Playgroud)