A Django beginner needs help here! I'm trying to upload image in a modal form, the problem is I can't submit my modal...when I click the submit button nothing actually happpen...been struggling this for 2 days... I'm using Bootstrap V 1.0.4 tried some JS codes from the net but none of them worked for me... any idea what should I do? thanks... here`s my modal:
Django初学者需要帮助!我试图以模态形式上传图像,问题是我无法提交我的模态...当我点击提交按钮时,实际上并没有真正开心...已经挣扎了2天......我正在使用Bootstrap V 1.0.4从网上尝试了一些JS代码,但它们都没有为我工作......任何想法我该怎么办?谢谢......这是我的模态:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">آپلود عکس</h4>
</div>
<div class="modal-body">
<p>کاربر گرامی لطفا قبل از آپلود عکس به موارد زیر توجه نمایید:</p>
<ul>
<li>حداکثر حجم قابل قبول برای فایل ارسالی 8 مگابایت می باشد</li>
<li>فرمت های تصویری مجاز: jpg , Gif , PNG</li>
<li>در صورت ارسال عکس های غیراخلاقی عکس و طرح شما به هیچ وجه منتشر نخواهد شد و پس از چاپ از سیستم حذف می گردد</li>
<li>لطفاً در هنگام آپلود عکس صبور باشید :)</li>
</ul>
</div>
<div class="modal-footer">
<form method="post" action="/upload/" id="formfield">
{% csrf_token %}
<div class="form-group">
<label for="upload">آپلود عکس:</label>
<input type="file" class="form-control" id="upload" name="upload"/>
</div>
<div class="form-group">
<label for="sides">چند رو بودن(1-پشت/2-جلو/3-هر دو طرف):</label>
<input type="text" class="form-control" id="sides" name="sides"/>
</div>
<button id="submit" type="submit" class="btn btn-default" data-dismiss="modal">ذخیره</button>
</form>
</div>
</div>
</div>
</div>
sorry the if the form is in persian. views.py
对不起,如果表格是波斯语。 views.py
def upload(request):
if request.method=='POST':
print "entered upload"
image=request.POST.get('upload', False)
sides=request.POST.get('sides', False)
design=Design.objects.create(image=image, sides=sides)
return HttpResponseRedirect("/home/")
since I cant submit my modal it doesn
t even enter my upload
def in views.py. any help would be greatly appreciated :)
因为我无法提交我的模态,它甚至不会在views.py中输入我的上传def。任何帮助将不胜感激 :)
1 个解决方案
#1
4
You have data-dismiss="modal"
on submit button, which is a bootstrap handler for closing the modal box. The bootstrap is catching this event and preventing default submit event as its purpose is to close the modal. Just remove the data-dismiss="modal"
from submit button and you are good to go. Also follow the tips by karthikr
您在提交按钮上有data-dismiss =“modal”,这是用于关闭模式框的引导处理程序。引导程序正在捕获此事件并阻止默认提交事件,因为其目的是关闭模式。只需从提交按钮中删除data-dismiss =“modal”就可以了。另请遵循karthikr的提示
#1
4
You have data-dismiss="modal"
on submit button, which is a bootstrap handler for closing the modal box. The bootstrap is catching this event and preventing default submit event as its purpose is to close the modal. Just remove the data-dismiss="modal"
from submit button and you are good to go. Also follow the tips by karthikr
您在提交按钮上有data-dismiss =“modal”,这是用于关闭模式框的引导处理程序。引导程序正在捕获此事件并阻止默认提交事件,因为其目的是关闭模式。只需从提交按钮中删除data-dismiss =“modal”就可以了。另请遵循karthikr的提示