1. 1146,Table ‘xxxx.django_session’ doesn’t exist"
在setting.py中添加SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
2.type object ‘Token’ has no attribute 'objects
这个在前后端分离中,重写userModel的save函数在中存储Token的时候会碰到。
解决办法:
# 添加 'rest_framework.authtoken' 至 settings.py 的 INSTALLED_APPS 中,
INSTALLED_APPS = [
'simpleui',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'rest_framework',
# 这里---------------------------------------
'rest_framework.authtoken',
# 然后执行
python manage.py makemigrations
python manage.py migrate
3. 如何咋admin中使某个字段显示为不可编辑
再对应app目录下的admin.py中,对某个admin类添加readonly_fields字段
示例代码:
@admin.register(JobListModel)
class JobListAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'type', 'per', 'create_time']
search_fields = ['name', 'type', 'per']
ordering = ['create_time']
list_filter = ['id', 'create_time', 'type', 'per']
# 这里---------------------------------------------------
readonly_fields = ['create_time']
list_per_page = 30
4. 基础userModel时报错auth.User.groups: (fields.E304) Reverse accessor for ‘User.groups’ clashes with reverse accessor for ‘User.groups’…
在setting.py中添加AUTH_USER_MODEL = 'users.UserProfile'即可
5. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
这个是pycharm配置的问题 点击编辑配置菜单进入配置编辑界面
在Environment variables中添加(记得和前面的配置中间要有分隔符冒号;)
DJANGO_SETTINGS_MODULE=manage_server.settings