问题描述
有关我正在做的项目的背景信息。这是一个自动散文检查系统,管理员用户应该能够在系统中添加,编辑和尝试问题。我可以在系统中添加文章,但无法编辑和尝试。每当我尝试编辑和尝试时,都会出现KeyError。
我不知道出错了,因为我使用我的教授的代码和他的工作重新创建了系统。 >
这是编辑和尝试问题的KeyError消息:
这里是views.py(它的很长)的代码:
我已经阅读了关于KeyError的Stack Overflow的很多解决方案,但是除了这个问题,除了这个问题,似乎没有什么帮助:。
根据该帖子的用户,他能够解决KeyError通过改变一些线。还有很多用户提到使用DICT.get(key),但在我看来,我目前的代码(views.py)已经在使用DICT方法了? (请纠正我,如果我错了!)
哦,谢谢你的帮助!我意识到我的愚蠢的错误...
以前我启动了django系统,使用这个使用端口8000的命令
python manage.py runserver
应该使用端口8080
python manage.py runserver 127.0.0.1:8080
A bit of background info about the project I'm doing. It's an automatic essay checking system and the admin user should be able to add, edit, and attempt questions in the system. I'm able to add essays to the system but was not able to edit and attempt. Whenever I try to edit and attempt, KeyError appears.
I'm not sure what went wrong because I recreated the system using my professor's code and his worked.
Here is the KeyError message for edit and attempt question:http://imgur.com/iH9OG07.png
And here is the code for views.py (its quite long):http://pastebin.com/88vvZJ6J
I've read a lot of solutions on Stack Overflow regarding KeyError but none of them seem to help except for this which comes close to my problem: Getting KeyError in my django code.
According to users from that post, he was able to solve the KeyError by changing some lines. And a lot of users mention about using DICT.get(key) but it seems to me that my current code (views.py) is already using the DICT method? (Please correct me if I'm wrong!)
Oh okay thanks for your help! I realised my stupid mistake...
Previously I booted up the django system using this command which uses port 8000
python manage.py runserver
Should have used port 8080 instead
python manage.py runserver 127.0.0.1:8080
这篇关于使用DICT.get(键)但仍然在Django中获取KeyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!