English 中文(简体)
配对 - 值差
原标题:django - valueError

我正在开发一个网络应用程序, 我在一个特性中遇到一个问题。 您可以在这里查看 < a href=> http://qlimp.com' rel=" nofollow" > http://qlimp.com 。 您也可以用这个来使用用户名/ password: supple/ dummy

登录后, 请单击链接 < 坚固> 。 移动以覆盖设置 。 您将看到可以上传图像的调色板, 输入一些文本 。

当您上传图像时, 我在 jQuery 中写了 ajax 请求, 该请求将图像上传到服务器, 并显示该图像的完整背景预览 。

J 查询

$( #id_tmpbg ).live( change , function()
    {
    $("#ajax-loader").show();
    $("#uploadform").ajaxForm({success: showResponse}).submit();
    });

function showResponse(responseText, statusText, xhr, $form)  { 
    $.backstretch(responseText)
    $("#ajax-loader").hide();
}

所以这里的问题是 当我上传图像时 它显示

ValueError at /cover/ 
The view cover.views.backgroundview didn t return an HttpResponse object. 
Request Method: POST Request URL: http://qlimp.com/cover/ 

我实际上是在视图中返回 HttpResponse 对象 。

视图. py :

@login_required
def backgroundview(request):
    if request.is_ajax():
        form = BackgroundModelForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                g = BackgroundModel.objects.get(user=request.user)
            except BackgroundModel.DoesNotExist:
                data = form.save(commit=False)
                data.user = request.user
                data.save()
            else:
                if g.tmpbg !=    and g.tmpbg != g.background:
                    image_path = os.path.join(settings.MEDIA_ROOT, str(g.tmpbg))
                    try:
                        os.unlink(image_path)
                    except:
                        pass
                data = BackgroundModelForm(request.POST, request.FILES, instance=g).save()
            return HttpResponse(data.tmpbg.url)
    else:
        form = BackgroundModelForm()
        return render_to_response("cover.html", { form : form}, context_instance=RequestContext(request))

模型. py :

class BackgroundModel(models.Model):
    user = models.OneToOneField(User)
    background = models.ImageField(upload_to= backgrounds , null=True, blank=True)
    tmpbg = models.ImageField(upload_to= backgrounds , null=True, blank=True)

class BackgroundModelForm(ModelForm):
    class Meta:
        model = BackgroundModel
        exclude = ( user , background )

But these things are working on my computer(save the image and shows the background preview) but not in the production server. Why is it so? I ve uploaded the same code to the server.

有人能帮我吗?

问题回答

如果表单有效,您将不返回回复。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签