数据不通过用户存储在数据库中

时间:2022-08-15 16:59:12

I want to store Username in database using raw data I have some this But I am getting error. Please help me with this.

我想使用原始数据将用户名存储在数据库中我有一些这样但我收到错误。请帮我解决一下这个。

#models.py

class signup(models.Model):
    username = models.CharField(max_length = 50)

    def __unicode__ (self):
        return self.username

#views.py

def sign(request):
    u = username.request.POST['username'])
    u.save()
    return render(request,'bookstore/signup.html',{'username':u})

and my error is :

我的错误是:

SyntaxError at /sign/invalid syntax (views.py, line 31)

语法错误/符号/无效语法(views.py,第31行)

1 个解决方案

#1


0  

In your view you need to import the signup model:

在您的视图中,您需要导入注册模型:

#views.py
from models import signup

def sign(request):
    username = request.POST['username']
    user = signup.objects.create(username=username)
    return render(request,'bookstore/signup.html',{'username': username})

#1


0  

In your view you need to import the signup model:

在您的视图中,您需要导入注册模型:

#views.py
from models import signup

def sign(request):
    username = request.POST['username']
    user = signup.objects.create(username=username)
    return render(request,'bookstore/signup.html',{'username': username})