小编yun*_*num的帖子

python中的搁置模块无法正常工作:"db type无法确定"

我试图在Python中创建一个简单的密码存储程序,它看起来很简单,所以我想知道我是否使用搁置错误.

我有主.py文件:

import shelve

passwords = shelve.open('./passwords_dict.py')

choice = raw_input("Add password (a) or choose site (c)?")

if choice[0] == 'a':
    site_key = raw_input("Add for which site? ").lower()
    userpass = raw_input("Add any info such as username, email, or passwords: ")

    passwords[site_key] = userpass

else:
    site = raw_input("Which site? ").lower()
    if site in passwords:
        print "Info for " + site + ": " + passwords[site]
    else:
        print site, "doesn't seem to exist!"

print "Done!"

passwords.close()
Run Code Online (Sandbox Code Playgroud)

而另一个文件passwords_dict.py只是一个空字典.

但是当我尝试运行该程序时,我收到此错误:

Traceback (most recent call last): …
Run Code Online (Sandbox Code Playgroud)

python shelve dbm persistent-storage python-2.7

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

将jQuery与Flask结合使用:如何防止表单提交时跳至页面顶部?

我在Flask中有一个单页网站,底部有联系表。如何防止浏览器在提交时跳到页面顶部?我不能使用return false,因为实际上没有发生任何显式的JavaScript。我正在使用Flask的WTForms。

<section id="contact">
<h2 class='contact'>Contact</h2>

{% if success %}
<p>Thanks for your message!</p>

{% else %}

{% for message in form.name.errors %}
<div class="flash">{{ message }}</div>

{% endfor %}

{% for message in form.email.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

{% for message in form.subject.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

{% for message in form.message.errors %}
<div class="flash">{{ message }}</div>
{% endfor %}

<form id="contactform" action="{{ url_for('contact') }}" method=post>
{{ form.hidden_tag() }}

## "autofocus=true" …
Run Code Online (Sandbox Code Playgroud)

validation jquery jinja2 flask

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