小编Imo*_*oum的帖子

如何按键对字典进行排序?

我试图按键排序dict但没有机会.这是我的词:

result={'1':'value1','2':'value2',...}
Run Code Online (Sandbox Code Playgroud)

我正在使用Python2.7,我发现了这一点

keys = result.keys()
keys.sort()
Run Code Online (Sandbox Code Playgroud)

但这不是我的预期,我有一个未分类的词典.

python sorting dictionary

24
推荐指数
2
解决办法
3万
查看次数

分配前引用的局部变量“服务器”

def websvc(currency):
    db = MySQLdb.connect("localhost", "root", "aqw", "PFE_Project")
    cursor = db.cursor()
    sql = "SELECT * FROM myform_composantsserveur"
        
    try:
        cursor.execute(sql)
        results = cursor.fetchall()
        currency_in = currency
        req = urllib2.urlopen('http://rate-exchange.appspot.com/currency?from=USD&to=%s') % (currency_in) 
        req1 = req.read()
        rate = int(req1['rate'])
        # rate = 0.77112893299999996
        
        servers = []
        for row in results:
            result = {} 
            result['1'] = row[1]
            result['3'] = int(row[2])
            result['4'] = int(row[3])
            result['5'] = int(row[4])
            result['6'] = row[5]
            result['7'] = int(row[6])
            result['8'] = row[7]
            result['9'] = row[8]
            p = rate * calculations_metric (int(row[2]), …
Run Code Online (Sandbox Code Playgroud)

python dictionary list

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

'url'需要非空的第一个参数.Django 1.5中的语法发生了变化,请参阅文档

我正在尝试使用django.contrib.auth登录,但似乎这在Django 1.5中不起作用这是urls.py

r'^login/$', 'django.contrib.auth.views.login',  {'template_name': 'login.html'}),
Run Code Online (Sandbox Code Playgroud)

这是我的模板

1   {% extends "website/base.html" %}
2   
3   {% block content %}
4   
5   {% if form.errors %}
6   <p>Authentication error</p>
7   {% endif %}
8   
9   <form action="{% url django.contrib.auth.views.login %}" method="post">
10    {% for field in form %}
11    <p>
12      {{ field.label_tag }}: {{ field }}
13      {{ field.errors }}
14    </p>
15    {% endfor %}
16    <p><input type="submit" value="Login" /></p>
17    <input type="hidden" name="next" value="{{ next }}" />
18  </form> …
Run Code Online (Sandbox Code Playgroud)

authentication django login

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

标签 统计

dictionary ×2

python ×2

authentication ×1

django ×1

list ×1

login ×1

sorting ×1