Python搭建服务问题汇总

10 阅读1分钟

1.RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods

解决:pip3 install cryptography

2.TypeError: student_list() missing 1 required positional argument: 'request'

解决:path('student_list/', views.student_list()), 改成

path('student_list/', views.student_list),

3.RuntimeError: Model class APP.models.Test doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

解决:依赖不到,需要在INSTALLED_APPS = ['myAppName.apps.myAppNameConfig',] 加上

这myAppNameConfig是命令在 apps.py 中生成的默认类.manage.py createapp myAppName。myAppName您的应用程序的名称在哪里。

4.django.db.utils.ProgrammingError: (1146, "Table 'autooffice.app_test' doesn't exist")

解决:要自动ORM要自动生成表,要执行

python3 manage.py makemigrations APP

python3 manage.py migrate

完成后,刷新数据库会看见 APP_test的

5.Django post 请求返回 403

解决:导入from django.views.decorators.csrf import csrf_exempt
在函数前面添加修饰器:@csrf_exempt

例:
@csrf_exempt

def runoob(request):

name = request.POST.get("name")