When I create a user via django admin panel, and mark it staff it can login django admin page as it should, but when I create user vie UserForm
and mark it as staff it can not login. It says invalid username password for staff and so on.
I suspect the error is because I am using,
TEMPLATE_CONTEXT_PROCESSORS = ('django.contrib.auth.context_processors.auth','django.core.context_processors.request')
Currently I have the following code:
user_form = UserForm(data=request.POST)
profile_form = UserProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
As form:
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields = ('username', 'email', 'password')
Now tell me, how can I by pass this problem?
three simple step:
user = User.objects.create_user("username")
set password for your user:
user.password = "your_password"
user.set_password(user.password)
make user as super user:
user.is_staff=True
user.is_superuser=True'
save your user:
user.save()
now you can login in admin panel of django
EDIT : instead of all above you can do just:
python manage.py createsuperuser
and create a super user
phew, I had to add something like this:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.