我正在使用引导程序模板。但是在将配置文件信息保存到数据库中出现了问题。这是我的代码。我不知道我是否做对了。但是它不起作用。
models.py
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
Propic = models.ImageField(upload_to="Banners/", null=True,blank=True)
bio = models.TextField(max_length=500, blank=True)
location = models.CharField(max_length=30, blank=True)
views.py
def profile(request):
ids = request.user.id
user = User.objects.get(pk=ids)
if request.method == "POST":
bio = request.POST["bio"]
location = request.POST["location"]
image = request.FILES['pic']
form = user.profile(bio = bio , location = location , propic=image)
form.save()
return HttpResponse("info saved")
return render(request, "dashbord/user.html", {"user": user })
相关分类