jquery フォーム プラグインhttp://jquery.malsup.com/form/#getting-startedを使用して、画像を django サーバー側にアップロードしています。エラーはありませんが、イメージは MEDIA_ROOT パスに保存されていません。過去 2 日間、さまざまな手法 (プラグインを試した) を試しましたが、何も機能していません。以下に、簡単にするためにすべてを示しました。
私のHTMLコード:
<form id="uploadform" method="post" enctype="multipart/form-data" action="background/">
<input type="file" name="photoimg" id="photoimg" />
</form>
Javascript コード:
https://gist.github.com/2377516
Django Models.py:
class BackgroundModel(models.Model):
user = models.OneToOneField(User)
background = models.ImageField(upload_to='backgrounds')
ジャンゴのviews.py:
def backgroundview(request):
if request.is_ajax():
b = request.POST.get('photoimg')
try:
g = BackgroundModel.objects.get(user=request.user)
except BackgroundModel.DoesNotExist:
bm = BackgroundModel(background=b)
bm.user = request.user
bm.save()
else:
g.background = b
g.save()
return HttpResponse("")
ジャンゴの設定.py:
MEDIA_ROOT = '/home/nirmal/try/files/'
MEDIA_URL = 'http://localhost:8000/files/'
ジャンゴのurls.py:
url(r'^cover/$', login_required(direct_to_template), {'template': 'cover.html'}),
url(r'^cover/background/$', 'cover.views.backgroundview'),
誰でも私を助けることができますか?
ありがとう!