社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

django image upload 问题大大来帮下忙把~~

pythondjango痴迷者 • 11 年前 • 7948 次点击  

my views.py

def upload(request):
    if request.user.is_authenticated():
            user = User.objects.get(pk=request.user.id)

            if request.method == "POST":
                    form = UploadForm(request.POST, request.FILES,instance=user)
                    #print form
                    if form.is_valid():
                            #m = Upload.objects.all()
                            #print m
                            instance=Upload(image=request.FILES['image'])
                            instance.save()
                            #m = Upload(image=image)
                            #print m
                            #m.save()
            #return HttpResponseRedirect(reverse('profile_edit'))
                    else:
                            form = UploadForm(instance=user)

                    return render_to_response('upload.html', { 'form' : form })
    return render_to_response("upload.html",{"user":user},context_instance=RequestContext(request))

my models.py

class Upload(models.Model):
        user        = models.OneToOneField(User)
        #email       = models.CharField(max_length=120)
        #description = models.TextField()
        #website     = models.CharField(max_length=512)
        image       = models.ImageField('Label', upload_to='static/media/')
        user_id     = models.IntegerField()

my forms.py

class UploadForm(ModelForm):
    class Meta:
       model = Upload
       exclude = ("user")

现在的问题是我的views函数中POST得到的data save不到mysql数据库中去 ~~~

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/72
 
7948 次点击  
文章 [ 5 ]  |  最新文章 11 年前