本文介绍了计算服务器端的结果,但会话数据不是每个用户隔离的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用户进行测试的Web应用上工作,他们在测试结束时看到他们的分数。
我计算服务器端的用户分数。问题在于,当用户进行测试时,会影响另一个用户进行另一测试的分数。我的意思是,如果用户A接受测试并且用户B也从另一系统接受测试,则在一天结束时,用户A将用户B的结果视为他的结果。真的不知道代码有什么问题。但下面是我计算用户分数的代码:
$ b

  def Compute_UserScore(self,details,ques_no):
try:
if(HomePage.answer_.strip()==):
self.response.write(< script type =text / javascript>
alert( 亲爱的用户,你无法两次回答相同的答案..再次测试!);
< / script>)
self.redirect('/ otherPages / subjectSelect.html')
else:
count = 0
HomePage.ans_no = 0
HomePage.unans_no = 0
HomePage.correct_no = 0
HomePage.wrong_no = 0
HomePage.failed_ques = list()
HomePage.answer_ = HomePage.answer_.strip()
question_1 = HomePage.question_.split(gcdc_split_format)
while(count!= (ques_no)):
user_answer = str(details [count])。strip()。capitalize()
re (len(str(user_answer).strip())== 1):
HomePage.ans_no = HomePage al_answer = str(HomePage.answer_ [count])。strip .ans_no + 1
if(user_answer.strip()== real_answer.strip()):
HomePage.correct_no = HomePage.correct_no + 1
else:
HomePage.wrong_no = HomePage.wrong_no + 1
HomePage.failed_ques.append(str(No。 + str(int((count + 1)))++ str(question_1 [count])))
else:
HomePage.unans_no = HomePage.unans_no + 1
count = count + 1
HomePage.answer_ =
除外:
self.redirect('/')
返回


解决方案

不确定您的主页是什么,但它似乎是全局变量或一个包名称
任何一个意味着你的web应用程序的每个用户都共享相同的内存存储(变量)作为测试结果。



这不是如果你想保存所有用户的测试结果,你应该有一个正确的方法,你应该有一种方法来识别不同的用户(即有用户登录),这样你可以为不同的用户显示不同的结果,并将结果保存在数据库或python字典中。

另一种方法是将结果保存在cookie中,cookie数据保存在客户端sid e,所以对于不同的用户会有所不同。


Working on a web app where user takes test and they see their score at the end of the test.I compute the user score on the server side. The problem is that, when a user take a test, it affect the score of another user taking another test. what i mean is if a user A takes a test, and a user B is taking a test also from another system, at the end of the day, user A sees user B result as his result. Really do not know what is wrong with the code. But below is my code for computing the user score

def Compute_UserScore(self, details, ques_no):
    try:
        if(HomePage.answer_.strip() == ""):
            self.response.write("""<script type = "text/javascript">
            alert("Dear User, You can not answer same answer twice.. Take test Again !");
            </script>""")
            self.redirect('/otherPages/subjectSelect.html')
        else:
            count = 0
            HomePage.ans_no = 0
            HomePage.unans_no = 0
            HomePage.correct_no = 0
            HomePage.wrong_no = 0
            HomePage.failed_ques = list()
            HomePage.answer_ = HomePage.answer_.strip()
            question_1 = HomePage.question_.split(" gcdc_split_format ")
            while (count != (ques_no)):
                user_answer = str(details[count]).strip().capitalize()
                real_answer = str(HomePage.answer_[count]).strip().capitalize()
                if (len(str(user_answer).strip()) == 1):
                    HomePage.ans_no = HomePage.ans_no + 1
                    if(user_answer.strip() == real_answer.strip()):
                        HomePage.correct_no = HomePage.correct_no + 1
                    else:
                        HomePage.wrong_no = HomePage.wrong_no + 1
                        HomePage.failed_ques.append(str("No. " + str(int((count + 1))) + "  " + str(question_1[count])))
                else:
                    HomePage.unans_no = HomePage.unans_no + 1
                count = count + 1
            HomePage.answer_ = ""
    except:
        self.redirect('/')
    return " "
解决方案

Not sure what your HomePage is but it seems to be a global variable or a package name.Either one means that every user of your web app is sharing the same memory storage (variables) for test result.

This is not the right way to do it if you want to save all users' test results. You should have a way to identify different users (i.e. having a user sign in) so you can show different results for a different user, and save the results in a database or in a python dictionary.

Another way to do it is to save the results in cookie, the cookie data is saved on the client side, so it would be different for different users.

这篇关于计算服务器端的结果,但会话数据不是每个用户隔离的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 11:11