[英]Django 'str' object is not callable and subuser register
Im try different method for user register.我尝试不同的用户注册方法。 I want to enroll a company staff user: I want to register method "companyname.staffusername" but I cant do register.
我想注册一个公司员工用户:我想注册方法“companyname.staffusername”但我不能注册。 How can I do it?
我该怎么做? Im try different way but I have error.
我尝试不同的方式,但我有错误。
I seen this error: "'str' object is not callable"我看到了这个错误:“'str' object is not callable”
Forms: Forms:
from django import forms
from django.db.models import fields
from .models import SubUser
class SubUserForm(forms.ModelForm):
class Meta:
model = SubUser
fields = ["Subusername","Subpassword","active","staff","Company"]
Views:意见:
from article.views import index
from user.views import loginUser
from django.contrib import messages
from django.contrib.auth import authenticate
from django.shortcuts import redirect, render
from . import forms
from .models import SubUser
# Create your views here.
def RegisterSubUser(request):
if request.method=="POST":
form = forms.SubUserForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get("Subusername")
password = form.cleaned_data.get("Subpassword")
newUser = SubUser(Subusername = username)
newUser.Subpassword(password)
newUser.save()
loginUser(request,newUser)
messages.success(request,"Kayıt Başarılı")
messages.warning(request,"DANGER")
return render(request,"index.html")
context ={
"form":form
}
return render(request,"register.html",context)
else:
form = forms.SubUserForm()
context ={
"form":form
}
return render(request,"register.html",context)
Models:楷模:
from django.db import models
# Create your models here.
class SubUser(models.Model):
Subusername = models.CharField(max_length=15,verbose_name="kullanıcı adı")
Subpassword = models.CharField(max_length=15,verbose_name="Parola")
active = models.BooleanField(default=True)
staff = models.BooleanField(default=True)
Company = models.ForeignKey("auth.User", on_delete= models.CASCADE,verbose_name="Çalıştığı Firma")
def __str__(self):
return self.Subusername
I think you get the error at我想你得到了错误
newUser.Subpassword(password)
Should be应该
newUser.Subpassword=password
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.