当我使用runserver时,它会发出以下警告消息:
(1_8.W001)Django 1.8中不推荐使用独立的TEMPLATE_*设置,TEMPLATES字典优先.您必须将以下设置的值放入默认的TEMPLATES dict:TEMPLATE_DEBUG.
Django文档:
"TEMPLATE_DEBUG从版本1.8开始不推荐使用:在DjangoTemplates后端的OPTIONS中设置'debug'选项."
这是我的settings.py与我徒劳的尝试修复它:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'myapp/templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': DEBUG,
'DEBUG': DEBUG,
'TEMPLATE_DEBUG': DEBUG
},
}, ]
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
我正在尝试为Django应用程序进行不区分大小写的登录,而不会更改原始用户名案例.根据我的研究,最好的方法是创建一个相关字段,以便在注册时以小写形式存储用户名.没有重塑用户模型,这是一个简单的解决方案,对吧?我的困境:如何从一个模型中获取数据,更改它,并在创建对象时将其保存在另一个模型中?
这是models.py中的内容:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User)
lc_n = User.username
lc_n = lc_n.lower()
lowercase_name = models.CharField(max_length=30, default=lc_n)
Run Code Online (Sandbox Code Playgroud)
运行时python manage.py makemigrations出现以下错误:
AttributeError: type object 'User' has no attribute 'username'
用户确实具有该属性,但无法以这种方式访问.
请原谅我,因为这必须包含一些简单的基本缺陷.我们将非常感谢您提供的任何支持.