小编ros*_*idh的帖子

使用Python + Selenium选择iframe

所以,我对如何在Selenium中做到这一点感到困惑,并且无法在任何地方找到答案,所以我分享了我的经验.

我试图选择一个iframe并且没有运气(或者无论如何都没有重复).HTML看起来像这样:

<iframe id="upload_file_frame" width="100%" height="465px" frameborder="0" framemargin="0" name="upload_file_frame" src="/blah/import/">
<html>
    <body>
        <div class="import_devices">
            <div class="import_type">
                <a class="secondary_button" href="/blah/blah/?source=blah">
                    <div class="import_choice_image">
                        <img alt="blah" src="/public/images/blah/import/blah.png">
                    </div>
                    <div class="import_choice_text">Blah Blah</div>
                </a>
            </div>
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Python代码(使用selenium库)试图使用以下方法找到这个iframe:

    @timed(650)
def test_pedometer(self):
    sel = self.selenium
    ...
    time.sleep(10)
    for i in range(5):
        try:
            if sel.select_frame("css=#upload_file_frame"): break
        except: pass
        time.sleep(10)
    else: self.fail("Cannot find upload_file_frame, the iframe for the device upload image buttons")
Run Code Online (Sandbox Code Playgroud)

我找到的Selenium命令的每个组合都重复失败.偶尔的成功是不可复制的,所以也许是某种竞争条件或其他什么?从来没有找到正确的方法来获得适当的硒.

python selenium

30
推荐指数
4
解决办法
5万
查看次数

在龙卷风中处理用户会话的标准方法

因此,为了避免"没有人最好的答案"问题,我将问,不是最好的方式,而是使用Tornado框架时处理会话的标准或最常用的方法.也就是说,如果我们不使用第三方认证(OAuth等),而是我们希望在浏览器中拥有我们自己的带有安全cookie的Users表,但是大多数会话信息存储在服务器上,那么最常见的做法是什么?我见过一些人使用Redis,有些人使用他们的普通数据库(MySQL或Postgres或其他),有些人使用memcached.

我正在处理的应用程序一次不会有数百万用户,甚至可能有数千个用户.但是,最终需要获得一些中等复杂的授权方案.我正在寻找的是确保我们不会做一些与一般Tornado社区不同的"奇怪"的事情,因为认证和授权虽然是我们需要的,但不是在我们产品的核心并不是我们应该区分自己的地方.所以,我们正在寻找大多数人(使用龙卷风)在这方面所做的事情,因此我认为这是一个(在理论上)客观真实答案的问题.

当然,理想的答案将指向示例代码.

python tornado

11
推荐指数
2
解决办法
1万
查看次数

django新字段生成"全局名称...未定义"错误

在django应用程序中,我有一个Word(需要学习)的模型,一个学生(学习它),而StudentWord是一个处理多对多关系的表:

class Word(models.Model):
    word = models.CharField(max_length=80)
    image = models.ForeignKey(Image)
    language = models.ForeignKey(Language)
    def __unicode__(self):
        return self.word

class Student(models.Model):
    username = models.ForeignKey(User)
    words = models.ManyToManyField(Word, through='StudentWord')
    def __unicode__(self):
        return self.username.username

class StudentWord(models.Model):
    word = models.ForeignKey(Word)
    student = models.ForeignKey(Student)
    level = models.IntegerField()
    nextdate = models.DateField()  <-- this field newly added
    learned = models.BooleanField()
    def __unicode__(self):
        return u'%s %s' % (self.student, self.word)
Run Code Online (Sandbox Code Playgroud)

我有它的工作,但想添加一个功能,应用程序会知道下一个日期是什么时候向学生询问这个词.为此,我将nextdate字段添加到StudentWord模型,删除了MySQL中的studentword表,使用syncdb重新生成它,并使用管理页面成功添加了几个学生用语(在其中添加了新的日期字段).

但是,视图的以下部分生成错误:

def index(request):
    last_question = request.session.get('last_question', 'none')
    student_language = request.session.get('student_language', 'english')
    student=Student.objects.get(username=request.user)
    words_student_knows = Word.objects.filter(studentword__student=student, studentword__learned=True)
    words_student_knows.filter(studentword__nextdate<=datetime.date.today())
Run Code Online (Sandbox Code Playgroud)

错误是:

Exception Type: …
Run Code Online (Sandbox Code Playgroud)

django datetime field model add

1
推荐指数
1
解决办法
4899
查看次数

django queryset排除第二个模型中的条目

我正在制作一个小词汇测验应用程序,一个单词的基本模型是这样的:

class Word(models.Model):
    id = models.AutoField(primary_key=True)
    word = models.CharField(max_length=80)
    id_image = models.ForeignKey(Image)
    def __unicode__(self):
        return self.word
    class Meta:
        db_table = u'word'
Run Code Online (Sandbox Code Playgroud)

我目前正在自我测验的单词模型是这样的:

class WordToWorkOn(models.Model):
    id = models.AutoField(primary_key=True)
    id_student = models.ForeignKey(Student)
    id_word = models.ForeignKey(Word)
    level = models.IntegerField()
    def __unicode__(self):
        return u'%s %s' % (self.id_word.__unicode__(), self.id_student.__unicode__() )
    class Meta:
        db_table = u'word_to_work_on'
Run Code Online (Sandbox Code Playgroud)

"水平"表示我学到了多少.我已经学过的一组单词有这个模型:

class WordLearned(models.Model):
    id = models.AutoField(primary_key=True)
    id_word = models.ForeignKey(Word, related_name='word_to_learn')
    id_student = models.ForeignKey(Student, related_name='student_learning_word')
    def __unicode__(self):
        return u'%s %s' % (self.id_word.__unicode__(), self.id_student.__unicode__() )
    class Meta:
        db_table = u'word_learned'
Run Code Online (Sandbox Code Playgroud)

当WordToWorkOn上的查询集返回时结果太少(因为它们已经足够好地学习以便移动到WordLearned并从WordToWorkOn中删除),我想找到要添加到其中的Word.我不知道一个好方法的部分是将它限制为尚未在WordLearned中的单词.

所以,一般来说,我想我想在一个单词的查询集上做某种类型的.exclude(),但它需要根据WordLearned表中的成员资格进行排除.有没有办法做到这一点?我发现有很多关于加入查询集的参考资料,但是找不到一个关于如何做到这一点的好文章(可能只是不知道要搜索的正确术语). …

django django-models django-queryset

0
推荐指数
1
解决办法
5274
查看次数