我通过执行创建User Profile应用程序和扩展User模块的整个过程为User添加了一个额外的字段.
它似乎没有错误.我无法弄清楚或在任何地方找到如何在管理员创建新用户的页面中显示此新字段.因此,根据个人信息,如名字和姓氏,我希望有我添加到用户个人资料的位置字段.
我的用户资料:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
# This field is required.
user = models.OneToOneField(User)
# Other fields here
location = models.CharField(max_length=20)
# definition of UserProfile from above
# ...
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
Run Code Online (Sandbox Code Playgroud)
我也想知道如何强制要求电子邮件,如密码和用户名.只需将Django文件夹中的用户模型更改为:
email = models.EmailField(_('e-mail address'), unique=True)
Run Code Online (Sandbox Code Playgroud)
完全不起作用.
[更新] 所以这是我创建的admin.py帽子.我应该在settings.py文件中将其包含在哪里,以便实际使用添加了用户模块和新表单的文件夹?我有这一行但它似乎并没有使用新的表单AUTH_PROFILE_MODULE ='UserProfile.UserProfile'(我有一个名为UserProfile的文件夹,其中包含两个snipets代码)
from django.contrib import admin
from django.contrib.auth.models import User,Group
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django …Run Code Online (Sandbox Code Playgroud) 我正在研究我的项目一段时间,最近注意到当我尝试转到localhost/admin /时会发出错误:
DoesNotExist at /admin/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: C:\Python27\lib\site-packages\django\db\models\query.py in get, line 349
Run Code Online (Sandbox Code Playgroud)
通常当我去那里它让我先登录然后重定向我,但现在它只是错误,除非我已经登录
我只能在我为用户创建的localhost登录功能中以管理员身份登录后进入我的管理员,然后转到该页面.此外,管理页面的注销停止工作,给出相同的错误.
我正在努力向用户模块添加一个新字段,并在发生这种情况时显示新的用户创建表单.
谁有类似的问题?或者有人知道是什么导致了这个?
我使用在Django中构建的password_reset函数为我的网站创建了一个Forgot Password功能,它发送了一封如下所示的电子邮件:
You're receiving this e-mail because you requested a password reset for your user account at example.com.
Please go to the following page and choose a new password:
http://example.com/reset/3/2zf-fe162b1d79f1b85c3630/
Your username, in case you've forgotten: Angie
Thanks for using our site!
The example.com team
Run Code Online (Sandbox Code Playgroud)
我会在哪里更改此电子邮件?