第一次使用Django-ckeditor,在注册了ckeditor_uploader,并配置好使用的时候,发现上传图片总是提示403禁止访问
开始猜想是csrf验证问题,于是注释掉:'django.middleware.csrf.CsrfViewMiddleware',再次上传,这次提示的不是403问题了,而是提示了500问题。这样就排除了CSRF问题了。去掉注释再次上传图片,查看具体报错如下:
DoesNotExist at /ckeditorbrowse/
article_list matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/ckeditorbrowse/?CKEditor=id_content&CKEditorFuncNum=3&langCode=zh-cn
Django Version: 3.2.8
Exception Type: DoesNotExist
Exception Value:
article_list matching query does not exist.
Exception Location: D:\Python39\lib\site-packages\django\db\models\query.py, line 435, in get
Python Executable: F:\lizhi\venv\Scripts\python.exe
Python Version: 3.9.7
Python Path:
['F:\\lizhi',
'F:\\lizhi',
'D:\\Program Files\\JetBrains\\PyCharm '
'2020.3.5\\plugins\\python\\helpers\\pycharm_display',
'D:\\Python39\\python39.zip',
'D:\\Python39\\DLLs',
'D:\\Python39\\lib',
'D:\\Python39',
'F:\\lizhi\\venv',
'F:\\lizhi\\venv\\lib\\site-packages',
'D:\\Python39\\lib\\site-packages',
'D:\\Python39\\lib\\site-packages\\win32',
'D:\\Python39\\lib\\site-packages\\win32\\lib',
'D:\\Python39\\lib\\site-packages\\Pythonwin',
'D:\\Program Files\\JetBrains\\PyCharm '
'2020.3.5\\plugins\\python\\helpers\\pycharm_matplotlib_backend']
Server time: Wed, 16 Mar 2022 14:52:48 +0000
大概的意思就是匹配的查询项目不存在。那就是URL配置问题了,再检查下URL规则,具体配置也没错误,猜想是顺序出了问题,于是改变顺序,再调试,成功了。下面将错误的与正确的顺序都贴下来给大家看看。
一、正确的
urlpatterns = [ path('admin/', admin.site.urls), path('',include('blog.urls')), path('ckeditor', include('ckeditor_uploader.urls')), ]二、错误的
urlpatterns = [ path('admin/', admin.site.urls), path('ckeditor', include('ckeditor_uploader.urls')), path('',include('blog.urls')), ]
评论