选择字段中所有编程语言的列表



我正在尝试创建一个WtForms SelectField,它将显示所有可供选择的各种编程语言。

几乎不可能在select字段中键入这里列出的所有编程语言。如何实现这种选择字段。

class SkillForm(Form):
    skill = SelectField('Languages', choices=[('c++', 'C++'), ('python', 'Python'), ('text', 'Plain Text')])
    submit = SubmitField('Submit')
    def validate_skill(self, field):
        if Skill.query.filter_by(author_id=current_user.id).filter(Skill.skill==field.data.lower()).first():
            raise ValidationError('Skill already exists.')

我刚刚添加了三个技能,只是为了测试的目的,它的工作,我需要包括所有可能的语言,它几乎不可能把它们都写在选择中,所以我从那里得到了什么其他的选择。

您可以通过运行脚本从网站获取所有语言:

#Get the html
import urllib2
response = urllib2.urlopen('http://en.wikipedia.org/wiki/List_of_programming_languages')
html = response.read()
#Parse it with beautifulsoup
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
langs = []
#Parse all the links.
for link in soup.find_all('a'):
    #Last link after ZPL, the last language.
    if link.get_text() == u'Top':
        break
    if link.get_text() == u'edit':
        pass
    else:
        langs.append(link.get_text())
# find u'See also'
see_also_index_ = langs.index(u'See also')
# strip out headers
langs = langs[see_also_index_+1:]
print langs

出于同样的原因,我创建了一个小型Github存储库,其中包含维基百科上列出的编程语言列表- http://en.wikipedia.org/wiki/List_of_programming_languages。它包含HTML复选框和下拉框。希望这对将来的人有所帮助

你可以查看这里的回购。https://github.com/chilarai/list-of-programming-languages

最新更新