玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容

python语法问题求助,django 1.5 自定义user模型

是django1.5的新特性,按照教程一步一步的操作感觉应该是无异的。折腾了半天不知道哪里问题。求大侠指点。
https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#auth-custom-user

已经按照教程做了这些工作:
1、新建了一个accounts的app,跟自定义用户相关(注册、登录等)的model 和 veiw 都写在里面
2、将accounts这个app已经添加到了settings.py的INSTALLED_APPS列表
3、在settings.py添加了AUTH_USER_MODEL = 'accounts.Passport'

下面是是accounts/的 models.py源码

# coding: utf8
from django.db import models
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser, PermissionsMixin

# Create your models here.


class Passport(AbstractBaseUser, PermissionsMixin):

    username = models.CharField(max_length=40, unique=True, db_index=True)
    email = models.EmailField(max_length=254, unique=True)
    avatar = models.ImageField(upload_to='avatar')
    nickname = models.CharField(max_length=60)

    is_staff = models.BooleanField('staff status', default=False)
    is_active = models.BooleanField('active', default=True)

    bio = models.CharField(max_length=255)

    GENRE_CHOICES = (
        (1, '摄影师'),
        (2, '插画师'),
        (3, '原画师'),
        (4, '平面设计师'),
        (5, '品牌顾问'),
        (6, '其他'),
    )
    genre = models.SmallIntegerField(choices=GENRE_CHOICES)
    site_dribbble = models.URLField(blank=True, verbose_name=u'Dribbble')
    site_deviantart = models.URLField(blank=True, verbose_name=u'DeviantART')
    site_benhance = models.URLField(blank=True, verbose_name=u'Benhance')
    site_tumblr = models.URLField(blank=True, verbose_name=u'Tumblr')
    site_zcool = models.URLField(blank=True, verbose_name=u'站酷')
    site_blog = models.URLField(blank=True, verbose_name=u'博客')
    site_sina = models.URLField(blank=True, verbose_name=u'新浪微博'

    ''' 【提示就这里语法错误!!!】 '''
    ''' 用于登录的字段 '''
    USERNAME_FIELD = 'username'
    '''
        REQUIRED_FIELDS must contain all required fields on your User model, 
        but should not contain the USERNAME_FIELD or password as these fields 
        will always be prompted for.
    '''
    REQUIRED_FIELD = ['email']

    objects = PassportManager()

    def get_full_name(self):
        return self.nickname

    def get_short_name(self):
        return self.nickname

    def __unicode__(self):
        return self.username



class PassportManager(BaseUserManager):

    def create_user(self, username, email, password=None):

        ''' create_user()参数必须是USERNAME_FIELD 和 所有的REQUIRED_FIELD '''

        if not email:
            raise ValueError('用户必须输入Email地址')

        user = self.model(
            username = username,
            email = PassportManager.normalize_email(email),
            is_staff = False,
            is_active = True,
            is_superuser = False
            )

        user.set_password(password)
        user.save(using = self._db)
        return user


    def create_superuser(self, username, email, password):

        user = self.create_user(
            username = username, 
            email = email, 
            password = password
            )

        user.is_staff = True
        user.is_active = True
        user.is_superuser = True

        user.save(using = self._db)
        return user


site_sina = models.URLField(blank=True, verbose_name=u'新浪微博'

前面这行的括号没有闭合。。。

秒看到

 site_sina = models.URLField(blank=True, verbose_name=u'新浪微博'

    ''' 【提示就这里语法错误!!!】 '''

少个括号....

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/wenda/wd19873.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月19日 - 10时21分50秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules