Django rest auth extend registration form
I am using Django-rest-auth for authentication and registration. I am using email to loging in the user with password. I want to store user's first name and last name at the time of registration (perhaps few more fields) i.e. On client side on registration form will have following fields(email, password, first name, last name, etc..). Currently registration form has only email, password 1 and password 2 fields and registration is basically successful.
My settings.py has following:
#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
#`allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
How can I achieve this?
django django-rest-framework django-rest-auth
add a comment |
I am using Django-rest-auth for authentication and registration. I am using email to loging in the user with password. I want to store user's first name and last name at the time of registration (perhaps few more fields) i.e. On client side on registration form will have following fields(email, password, first name, last name, etc..). Currently registration form has only email, password 1 and password 2 fields and registration is basically successful.
My settings.py has following:
#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
#`allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
How can I achieve this?
django django-rest-framework django-rest-auth
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26
add a comment |
I am using Django-rest-auth for authentication and registration. I am using email to loging in the user with password. I want to store user's first name and last name at the time of registration (perhaps few more fields) i.e. On client side on registration form will have following fields(email, password, first name, last name, etc..). Currently registration form has only email, password 1 and password 2 fields and registration is basically successful.
My settings.py has following:
#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
#`allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
How can I achieve this?
django django-rest-framework django-rest-auth
I am using Django-rest-auth for authentication and registration. I am using email to loging in the user with password. I want to store user's first name and last name at the time of registration (perhaps few more fields) i.e. On client side on registration form will have following fields(email, password, first name, last name, etc..). Currently registration form has only email, password 1 and password 2 fields and registration is basically successful.
My settings.py has following:
#This is required otherwise it asks for email server
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
#Following is added to enable registration with email instead of username
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
#`allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
How can I achieve this?
django django-rest-framework django-rest-auth
django django-rest-framework django-rest-auth
asked Apr 22 '16 at 18:17
NitishNitish
1,84252669
1,84252669
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26
add a comment |
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26
add a comment |
1 Answer
1
active
oldest
votes
If you want to extend the registration form, you're going to need to create your own custom user that has more fields.
So in your models file have this
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,
)
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
first_name = models.TextField(default='')
last_name = models.TextField(default='')
#any other fields you want
USERNAME_FIELD = 'email'
then in your settings you want this
AUTH_USER_MODEL = 'app_name.CustomUser'
and then django rest should use this user model as when you visit this form page
I hope this helps!
EDIT
I believe this should automatically handle passwords since it extends AbtractBaseUser, let me know if it doesn't
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36800770%2fdjango-rest-auth-extend-registration-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to extend the registration form, you're going to need to create your own custom user that has more fields.
So in your models file have this
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,
)
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
first_name = models.TextField(default='')
last_name = models.TextField(default='')
#any other fields you want
USERNAME_FIELD = 'email'
then in your settings you want this
AUTH_USER_MODEL = 'app_name.CustomUser'
and then django rest should use this user model as when you visit this form page
I hope this helps!
EDIT
I believe this should automatically handle passwords since it extends AbtractBaseUser, let me know if it doesn't
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
|
show 3 more comments
If you want to extend the registration form, you're going to need to create your own custom user that has more fields.
So in your models file have this
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,
)
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
first_name = models.TextField(default='')
last_name = models.TextField(default='')
#any other fields you want
USERNAME_FIELD = 'email'
then in your settings you want this
AUTH_USER_MODEL = 'app_name.CustomUser'
and then django rest should use this user model as when you visit this form page
I hope this helps!
EDIT
I believe this should automatically handle passwords since it extends AbtractBaseUser, let me know if it doesn't
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
|
show 3 more comments
If you want to extend the registration form, you're going to need to create your own custom user that has more fields.
So in your models file have this
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,
)
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
first_name = models.TextField(default='')
last_name = models.TextField(default='')
#any other fields you want
USERNAME_FIELD = 'email'
then in your settings you want this
AUTH_USER_MODEL = 'app_name.CustomUser'
and then django rest should use this user model as when you visit this form page
I hope this helps!
EDIT
I believe this should automatically handle passwords since it extends AbtractBaseUser, let me know if it doesn't
If you want to extend the registration form, you're going to need to create your own custom user that has more fields.
So in your models file have this
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin,
)
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
first_name = models.TextField(default='')
last_name = models.TextField(default='')
#any other fields you want
USERNAME_FIELD = 'email'
then in your settings you want this
AUTH_USER_MODEL = 'app_name.CustomUser'
and then django rest should use this user model as when you visit this form page
I hope this helps!
EDIT
I believe this should automatically handle passwords since it extends AbtractBaseUser, let me know if it doesn't
answered Apr 22 '16 at 18:26
Charles HaroCharles Haro
1,00811230
1,00811230
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
|
show 3 more comments
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
It gives me in console> django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'flights.CustomUser' that has not been installed. Before migrating of course, should I migrate?
– Nitish
Apr 22 '16 at 18:39
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
yea you need to migrate :)
– Charles Haro
Apr 22 '16 at 18:42
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
It gives me same error when I do migration
– Nitish
Apr 22 '16 at 18:45
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
did you do makemigrations before migrating?
– Charles Haro
Apr 22 '16 at 18:46
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
ERROR: django.db.utils.ProgrammingError: (1146,"Table'swarms_flight.flights_customuser_user_permissions' doesn't exist")
– Nitish
Apr 22 '16 at 18:55
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36800770%2fdjango-rest-auth-extend-registration-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you clarify what you want to do? Are you trying to extend the user model to add more fields?
– Charles Haro
Apr 22 '16 at 18:20
I am not sure if I am actually extending user model, now I have to go in my admin interface and manually add first name , last name etc. attributes to a user. I want to have these fields in my registration form so that on successful registration this data is automatically saved for newly created user.
– Nitish
Apr 22 '16 at 18:24
Ok i think I know what you want to do, look at my answer below
– Charles Haro
Apr 22 '16 at 18:26