简体   繁体   中英

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?

我认为您需要删除双引号。就像下面这样,

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

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'], ...)

如其他人所评论,删除引用在request.POST [........周围的引号。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM