Django rest auth extend registration form












1















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.



enter image description here



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?










share|improve this question























  • 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
















1















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.



enter image description here



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?










share|improve this question























  • 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














1












1








1








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.



enter image description here



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?










share|improve this question














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.



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












1 Answer
1






active

oldest

votes


















2














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






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









2














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






share|improve this answer
























  • 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
















2














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






share|improve this answer
























  • 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














2












2








2







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas