使用命令python manage.py mikegrations
进行数据迁移时,出现下面的异常:
RuntimeError: Model class apps.app_user.models.user_profile doesn't declare an explicit app_laation in INSTALLED_APPS.
相应的代码段是:
from django.shortcuts import render
from django.db.models import Q
from .models import user_profile
from django.contrib.auth.backend import ModelBackend
def main_site(request):
return render(request,'main_site.html')
class custom_backend(ModelBackend):
def authenticate(self,username=None,password=None,**kwargs):
try:
user = user_profile.object.get(Q(username=username)|Q(email=username))# 这里引入Q是或者的意思
if user.check_password(password):
return user
except Exception as e:
return None
这是由于第3行中,python3中不支持相对路径的引用,所以改成下面的代码——使用绝对路径即可:
from ap_user.models import user_profile