Django的。 '字符串索引必须是整数,而不是unicode'

时间:2012-09-25 18:51:44

标签: django django-admin

当我在管理站点中运行此操作时(向选定的人发送电子邮件)我有错误:

字符串索引必须是整数,而不是unicode django [p.user_email])

如何解决?

from django.contrib import admin
from myproject.myapp.models import People
from django.core.mail import send_mail

def send_mail(modeladmin, request, queryset):
    for p in queryset:
        send_mail('People information', p.name, p.time, 'mymail@gmail.com'
    [p.user_email])
send_mail.short_description = u'Send e-mail to selected people'

class PeopleAdmin(admin.ModelAdmin):
    list_display = ('name', 'user_email','time')
    actions = [send_mail]

admin.site.register(People, PeopleAdmin)

1 个答案:

答案 0 :(得分:0)

实际上,您忘记了'mymail@gmail.com'之后的逗号,因此它将其解释为'mymail@gmail.com'[p.user_email],就像您尝试索引字符串文字一样。