Django重新样式表

时间:2018-09-09 10:06:14

标签: python django forms

我目前正在尝试“设置”表单样式。总的来说,我得到了这个概念的支持,但那时还没有:

这是预定的方式(不起作用):

def signup (request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO, "Thanks for you registration, you are now able to login.")
            return redirect(reverse('post_list'))
    else:
        form = RegistrationForm()

        args = {'form': form}
        return render(request, 'registration/signup.html', args)

views.py:

class RegistrationForm(UserCreationForm):
    user = forms.CharField(required=True)

    class Meta:
        model = User
        fields = (
            'user',
            'password1',
            'password2',
            'pubpgp'
        )

    captcha = CaptchaField()

    def save(self, commit=True):
        user = super(RegistrationForm, self).save(commit=False)
        user.pubpgp = self.cleaned_data['pubpgp']

        if commit:
            user.save()

        return user

我得到的错误是:

  

AttributeError:管理器不可用; 'auth.User'已被交换   为“ accounts.User”

在我的settings.py中,我设置了:

  

AUTH_USER_MODEL ='帐户用户'

这是当前的工作状态:

#User Model Manager
class UserManager(BaseUserManager):
    def create_user(self, user, password=None):
        """
        Creates and saves a User with the given username and password.
        """
        if not user:
            raise ValueError('Error: The User you want to create must have a username, try again')

        new_user = self.model(
            user=self.model.normalize_username(user)
        )

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

    def create_staffuser(self, user, password):
        """
        Creates and saves a staff user with the given username and password.
        """
        new_user = self.create_user(
            user,
            password=password,
        )
        new_user.staff = True
        new_user.save(using=self._db)
        return new_user

    def create_superuser(self, user, password):
        """
        Creates and saves a superuser with the given username and password.
        """
        new_user = self.create_user(
            user,
            password=password,
        )
        new_user.staff = True
        new_user.admin = True
        new_user.save(using=self._db)
        return new_user


class User(AbstractBaseUser):

    #User fields
    user = models.CharField(verbose_name='username',max_length=30,unique=True)
    bio = models.TextField(max_length=5000, blank=True, null=True)
    pubpgp = models.TextField(blank=True, null=True)
    avatar = fields.ImageField(upload_to='avatar', blank=True, null=True, dependencies=[
        FileDependency(processor=ImageProcessor(
            format='JPEG', scale={'max_width': 350, 'max_height': 350}))
    ])

    #Account typs
    active = models.BooleanField(default=True)
    staff = models.BooleanField(default=False) # a admin user; non super-user
    admin = models.BooleanField(default=False) # a superuser
    # notice the absence of a "Password field", that's built in.

    USERNAME_FIELD = 'user'
    REQUIRED_FIELDS = [] # Username & Password are required by default.

    def get_full_name(self):
        # The user is identified by their Username ;)
        return self.user

    def get_short_name(self):
        # The user is identified by their Username address
        return self.user
    def __str__(self):
        return self.user

    def has_perm(self, perm, obj=None):
        """Does the user have a specific permission?"""
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, app_label):
        """Does the user have permissions to view the app `app_label`?"""
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_staff(self):
        """Is the user a member of staff?"""
        return self.staff

    @property
    def is_admin(self):
        """Is the user a admin member?"""
        return self.admin

    @property
    def is_active(self):
        """Is the user active?"""
        return self.active

    objects = UserManager()

帐户用户模型:

library(ncdf4)
setwd("E:\\KKIM_2017\\DES\\")

nc = nc_open("MTS_IR_201612010000.nc")       #open ncdf and read variables
lon = ncvar_get(nc,"longitude")              # Lon lat and time
lat = ncvar_get(nc,"latitude")
time = ncvar_get(nc, "time")
dname = "IR"  #variable
variabel = ncvar_get(nc,dname)
lonlat = as.matrix(expand.grid(lon,lat))
var_vektor = as.vector(variabel)
datanya = data.frame(cbind(lonlat,var_vektor))
names(datanya) = c("lon","lat",paste(dname,as.character(), sep="_"))
head(na.omit(datanya))
csvpath = "E:\\"  #directory to save file
csvname = "hasil_1v2.csv" #file_output
csvfile = paste(csvpath, csvname, sep="")
write.table(na.omit(datanya),csvfile, row.names=FALSE, sep=",")

我想我必须以某种方式将用户模型传递给此表单。对语法有任何了解吗?

0 个答案:

没有答案