V. Snow
V. Snow

Reputation: 133

User.objects.create() does nothing. (Django)

I have a view that should run User.objects.create() for the user registration.

User.objects.create(name="request.POST['name']", username="request.POST['username']", password="request.POST['password']")

It obviously passes the conditionals into this code because it runs the redirect I put after it.

But When testing the registration, it just doesn't create a new entry in the database. What's wrong with it?

Upvotes: 0

Views: 617

Answers (3)

aspo
aspo

Reputation: 374

Remove the quotes wrapped around request.POST[........ as others have commented.

Upvotes: -1

Chamath Ranasinghe
Chamath Ranasinghe

Reputation: 422

I think you need to remove double quotations.Like below,

User.objects.create(name=request.POST['name'], username=request.POST['username'], password=request.POST['password'])

Upvotes: 2

Moses Koledoye
Moses Koledoye

Reputation: 78554

You have your parameters wrapped in quotes which is not doing what you actually want.

Remove the quotes to properly access request.POST and put in the appropriate data:

User.objects.create(name=request.POST['name'], ...)

Upvotes: 1

Related Questions