User Registration: Creating user accounts Django 2.1.5Extending the User model with custom fields in DjangoDoes Django scale?Form validations in a template if using a readymade module for registrationWay to create multiline comments in Python?differentiate null=True, blank=True in djangoMongoEngine — how to custom User model / custom backend for authenticate()Django redirects to login page even after logging incustom user registration form in djangodjango authenticate() allways returns NoneUser login, authentication, and sign up in Django 1.10

Is Borg adaptation only temporary?

How were US credit cards verified in-store in the 1980's?

Is there anything in the universe that cannot be compressed?

Could a complex system of reaction wheels be used to propel a spacecraft?

Who declared the Last Alliance to be the "last" and why?

Why do presidential pardons exist in a country having a clear separation of powers?

What is the motivation behind designing a control stick that does not move?

Calculate Landau's function

How would a disabled person earn their living in a medieval-type town?

Does FERPA require parental notification of disability assessment?

Break down the phrase "shitsurei shinakereba naranaindesu"

Moscow SVO airport, how to avoid scam taxis without pre-booking?

apt-file regex: find multiple packages at once using or

Welche normative Autorität hat der Duden? / What's the normative authority of the Duden?

Can a system of three stars exist?

Could a simple hospital oxygen mask protect from aerosol poison?

The correct way of compute indicator function in Mathematica

How did the Altair 8800 front panel load the program counter?

Where should I draw the line on follow up questions from previous employer

A vector is defined to have a magnitude and *a* direction, but the zero vector has no *single* direction. So, how is the zero vector a vector?

How to differentiate between two people with the same name in a story?

How to load files as a quickfix window at start-up

IList<T> implementation

Where does MyAnimeList get their data from?



User Registration: Creating user accounts Django 2.1.5


Extending the User model with custom fields in DjangoDoes Django scale?Form validations in a template if using a readymade module for registrationWay to create multiline comments in Python?differentiate null=True, blank=True in djangoMongoEngine — how to custom User model / custom backend for authenticate()Django redirects to login page even after logging incustom user registration form in djangodjango authenticate() allways returns NoneUser login, authentication, and sign up in Django 1.10






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm having some trouble creating new accounts and then authenticating. I enter all the credentials in (username, password), and select "submit", and it successfully redirects me back to the 'account successfully created page'. However i can't find the new user account in the database and on the staff account.



This is my views file



from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login

# Create your views here.
def index(request):
return render(request, 'user_example/index.html')

def register(request):
if request.method=='POST':
form=UserCreationForm(request.POST)


if form.is_valid():
form.save()
username=form.cleaned_data.get('username')
raw_password=form.cleaned_data.get('password1')
'''user=User.objects.create_user(username=username, password=raw_password)
user.save()'''
user=authenticate(username=username, password=raw_password)
user.save()
#if user1 is not None:
login(request, user)
return redirect('success')

else:
form=UserCreationForm()


#context='form': form
return render(request, 'registration/register.html', 'form': form) #as

def success(request):
return render(request, 'user_example/success.html')


This is my success template:



<!DOCTYPE html>
<html>
<head>
<title>Successfull!</title>
</head>
<body>
% if user.is_authenticated %
<h1>Congratulations user.username !! you have successfully created an account.</h1>
% endif %
<p>You can go back to the<a href="% url 'index' %"> homepage
</a>now.</p>

</body>
</html>


This is my register template:



% block title %Register% endblock %
% block register_active %active% endblock %

% block body %
<div class="container-fluid">

<div class="row">
<div class="col-sm-12 col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h3>Create an Account</h3>
% if error_message %
<p><strong> error_message </strong></p>
% endif %
<form class="form-horizontal" role="form" action="% url 'success' %" method="post" enctype="multipart/form-data">
% csrf_token %
% include 'user_example/form-template.html' %
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<br>
<p><strong>-- OR --</strong></p>
<div class="panel-footer">
% load socialaccount %
<a href="% provider_login_url 'github' %">SignUp with Github</a>
}
</div>
<div class="panel-footer">
Already have an account? <a href="">Click here</a> to log in.
</div>
</div>
</div>
</div>

</div>

% endblock %


Please help, what am i doing wrong here?










share|improve this question





















  • 1





    Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

    – user9727749
    Mar 28 at 0:19











  • Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

    – Duke Sanmi
    Mar 28 at 13:21











  • Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

    – user9727749
    Mar 28 at 18:48

















1















I'm having some trouble creating new accounts and then authenticating. I enter all the credentials in (username, password), and select "submit", and it successfully redirects me back to the 'account successfully created page'. However i can't find the new user account in the database and on the staff account.



This is my views file



from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login

# Create your views here.
def index(request):
return render(request, 'user_example/index.html')

def register(request):
if request.method=='POST':
form=UserCreationForm(request.POST)


if form.is_valid():
form.save()
username=form.cleaned_data.get('username')
raw_password=form.cleaned_data.get('password1')
'''user=User.objects.create_user(username=username, password=raw_password)
user.save()'''
user=authenticate(username=username, password=raw_password)
user.save()
#if user1 is not None:
login(request, user)
return redirect('success')

else:
form=UserCreationForm()


#context='form': form
return render(request, 'registration/register.html', 'form': form) #as

def success(request):
return render(request, 'user_example/success.html')


This is my success template:



<!DOCTYPE html>
<html>
<head>
<title>Successfull!</title>
</head>
<body>
% if user.is_authenticated %
<h1>Congratulations user.username !! you have successfully created an account.</h1>
% endif %
<p>You can go back to the<a href="% url 'index' %"> homepage
</a>now.</p>

</body>
</html>


This is my register template:



% block title %Register% endblock %
% block register_active %active% endblock %

% block body %
<div class="container-fluid">

<div class="row">
<div class="col-sm-12 col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h3>Create an Account</h3>
% if error_message %
<p><strong> error_message </strong></p>
% endif %
<form class="form-horizontal" role="form" action="% url 'success' %" method="post" enctype="multipart/form-data">
% csrf_token %
% include 'user_example/form-template.html' %
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<br>
<p><strong>-- OR --</strong></p>
<div class="panel-footer">
% load socialaccount %
<a href="% provider_login_url 'github' %">SignUp with Github</a>
}
</div>
<div class="panel-footer">
Already have an account? <a href="">Click here</a> to log in.
</div>
</div>
</div>
</div>

</div>

% endblock %


Please help, what am i doing wrong here?










share|improve this question





















  • 1





    Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

    – user9727749
    Mar 28 at 0:19











  • Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

    – Duke Sanmi
    Mar 28 at 13:21











  • Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

    – user9727749
    Mar 28 at 18:48













1












1








1








I'm having some trouble creating new accounts and then authenticating. I enter all the credentials in (username, password), and select "submit", and it successfully redirects me back to the 'account successfully created page'. However i can't find the new user account in the database and on the staff account.



This is my views file



from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login

# Create your views here.
def index(request):
return render(request, 'user_example/index.html')

def register(request):
if request.method=='POST':
form=UserCreationForm(request.POST)


if form.is_valid():
form.save()
username=form.cleaned_data.get('username')
raw_password=form.cleaned_data.get('password1')
'''user=User.objects.create_user(username=username, password=raw_password)
user.save()'''
user=authenticate(username=username, password=raw_password)
user.save()
#if user1 is not None:
login(request, user)
return redirect('success')

else:
form=UserCreationForm()


#context='form': form
return render(request, 'registration/register.html', 'form': form) #as

def success(request):
return render(request, 'user_example/success.html')


This is my success template:



<!DOCTYPE html>
<html>
<head>
<title>Successfull!</title>
</head>
<body>
% if user.is_authenticated %
<h1>Congratulations user.username !! you have successfully created an account.</h1>
% endif %
<p>You can go back to the<a href="% url 'index' %"> homepage
</a>now.</p>

</body>
</html>


This is my register template:



% block title %Register% endblock %
% block register_active %active% endblock %

% block body %
<div class="container-fluid">

<div class="row">
<div class="col-sm-12 col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h3>Create an Account</h3>
% if error_message %
<p><strong> error_message </strong></p>
% endif %
<form class="form-horizontal" role="form" action="% url 'success' %" method="post" enctype="multipart/form-data">
% csrf_token %
% include 'user_example/form-template.html' %
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<br>
<p><strong>-- OR --</strong></p>
<div class="panel-footer">
% load socialaccount %
<a href="% provider_login_url 'github' %">SignUp with Github</a>
}
</div>
<div class="panel-footer">
Already have an account? <a href="">Click here</a> to log in.
</div>
</div>
</div>
</div>

</div>

% endblock %


Please help, what am i doing wrong here?










share|improve this question
















I'm having some trouble creating new accounts and then authenticating. I enter all the credentials in (username, password), and select "submit", and it successfully redirects me back to the 'account successfully created page'. However i can't find the new user account in the database and on the staff account.



This is my views file



from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login

# Create your views here.
def index(request):
return render(request, 'user_example/index.html')

def register(request):
if request.method=='POST':
form=UserCreationForm(request.POST)


if form.is_valid():
form.save()
username=form.cleaned_data.get('username')
raw_password=form.cleaned_data.get('password1')
'''user=User.objects.create_user(username=username, password=raw_password)
user.save()'''
user=authenticate(username=username, password=raw_password)
user.save()
#if user1 is not None:
login(request, user)
return redirect('success')

else:
form=UserCreationForm()


#context='form': form
return render(request, 'registration/register.html', 'form': form) #as

def success(request):
return render(request, 'user_example/success.html')


This is my success template:



<!DOCTYPE html>
<html>
<head>
<title>Successfull!</title>
</head>
<body>
% if user.is_authenticated %
<h1>Congratulations user.username !! you have successfully created an account.</h1>
% endif %
<p>You can go back to the<a href="% url 'index' %"> homepage
</a>now.</p>

</body>
</html>


This is my register template:



% block title %Register% endblock %
% block register_active %active% endblock %

% block body %
<div class="container-fluid">

<div class="row">
<div class="col-sm-12 col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<h3>Create an Account</h3>
% if error_message %
<p><strong> error_message </strong></p>
% endif %
<form class="form-horizontal" role="form" action="% url 'success' %" method="post" enctype="multipart/form-data">
% csrf_token %
% include 'user_example/form-template.html' %
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<br>
<p><strong>-- OR --</strong></p>
<div class="panel-footer">
% load socialaccount %
<a href="% provider_login_url 'github' %">SignUp with Github</a>
}
</div>
<div class="panel-footer">
Already have an account? <a href="">Click here</a> to log in.
</div>
</div>
</div>
</div>

</div>

% endblock %


Please help, what am i doing wrong here?







django python-3.x authentication django-users django-2.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 14:12







Duke Sanmi

















asked Mar 27 at 23:18









Duke SanmiDuke Sanmi

163 bronze badges




163 bronze badges










  • 1





    Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

    – user9727749
    Mar 28 at 0:19











  • Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

    – Duke Sanmi
    Mar 28 at 13:21











  • Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

    – user9727749
    Mar 28 at 18:48












  • 1





    Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

    – user9727749
    Mar 28 at 0:19











  • Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

    – Duke Sanmi
    Mar 28 at 13:21











  • Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

    – user9727749
    Mar 28 at 18:48







1




1





Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

– user9727749
Mar 28 at 0:19





Why did you comment out user=User.objects.create_user... ? That is the function creating and saving your user.

– user9727749
Mar 28 at 0:19













Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

– Duke Sanmi
Mar 28 at 13:21





Because it gave the same outcome still i'm getting now. Just added the ''success template'' code to it.. what else could be the problem?

– Duke Sanmi
Mar 28 at 13:21













Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

– user9727749
Mar 28 at 18:48





Can you include your User model and model manager. Will need to see that create_user function. Are you calling save() within it?

– user9727749
Mar 28 at 18:48












1 Answer
1






active

oldest

votes


















0















In your given code, you'd commented out the essential part :( Remove that comment, That's it :)


Apart from that, the user.save() statement is irrelevant, because the create_user() method will save the user to the DB.



def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)

if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# uncomment below line
user = User.objects.create_user(username=username, password=raw_password)

user.save() # remove this line

user = authenticate(username=username, password=raw_password)
user.save()
# if user1 is not None:
login(request, user)
return redirect('success')

else:
form = UserCreationForm()

return render(request, 'registration/register.html', 'form': form)





share|improve this answer

























  • Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

    – Duke Sanmi
    Mar 28 at 14:19










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%2f55387931%2fuser-registration-creating-user-accounts-django-2-1-5%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









0















In your given code, you'd commented out the essential part :( Remove that comment, That's it :)


Apart from that, the user.save() statement is irrelevant, because the create_user() method will save the user to the DB.



def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)

if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# uncomment below line
user = User.objects.create_user(username=username, password=raw_password)

user.save() # remove this line

user = authenticate(username=username, password=raw_password)
user.save()
# if user1 is not None:
login(request, user)
return redirect('success')

else:
form = UserCreationForm()

return render(request, 'registration/register.html', 'form': form)





share|improve this answer

























  • Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

    – Duke Sanmi
    Mar 28 at 14:19















0















In your given code, you'd commented out the essential part :( Remove that comment, That's it :)


Apart from that, the user.save() statement is irrelevant, because the create_user() method will save the user to the DB.



def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)

if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# uncomment below line
user = User.objects.create_user(username=username, password=raw_password)

user.save() # remove this line

user = authenticate(username=username, password=raw_password)
user.save()
# if user1 is not None:
login(request, user)
return redirect('success')

else:
form = UserCreationForm()

return render(request, 'registration/register.html', 'form': form)





share|improve this answer

























  • Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

    – Duke Sanmi
    Mar 28 at 14:19













0














0










0









In your given code, you'd commented out the essential part :( Remove that comment, That's it :)


Apart from that, the user.save() statement is irrelevant, because the create_user() method will save the user to the DB.



def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)

if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# uncomment below line
user = User.objects.create_user(username=username, password=raw_password)

user.save() # remove this line

user = authenticate(username=username, password=raw_password)
user.save()
# if user1 is not None:
login(request, user)
return redirect('success')

else:
form = UserCreationForm()

return render(request, 'registration/register.html', 'form': form)





share|improve this answer













In your given code, you'd commented out the essential part :( Remove that comment, That's it :)


Apart from that, the user.save() statement is irrelevant, because the create_user() method will save the user to the DB.



def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)

if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')

# uncomment below line
user = User.objects.create_user(username=username, password=raw_password)

user.save() # remove this line

user = authenticate(username=username, password=raw_password)
user.save()
# if user1 is not None:
login(request, user)
return redirect('success')

else:
form = UserCreationForm()

return render(request, 'registration/register.html', 'form': form)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 2:54









JPGJPG

22.3k3 gold badges14 silver badges46 bronze badges




22.3k3 gold badges14 silver badges46 bronze badges















  • Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

    – Duke Sanmi
    Mar 28 at 14:19

















  • Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

    – Duke Sanmi
    Mar 28 at 14:19
















Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

– Duke Sanmi
Mar 28 at 14:19





Thanks for the response, however before i commented that line out i tried to run it like that but it still won't create the user account so what else maybe the problem. I added my templates to give better understanding.

– Duke Sanmi
Mar 28 at 14:19








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















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%2f55387931%2fuser-registration-creating-user-accounts-django-2-1-5%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현