我正在开发一个网络应用程序, 我在一个特性中遇到一个问题。 您可以在这里查看 < a href=> http://qlimp.com' rel=" nofollow" > http://qlimp.com a> 。 您也可以用这个来使用用户名/ 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.
有人能帮我吗?