New File

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#file.

html

<form action="image" method="post" enctype="multipart/form-data">


{% csrf_token %}
<label>Flower Name</label>
<input type="text" placeholder="name" name="fl">
<label>Flower price</label>
<input type="text" placeholder="price" name="pr">
<label>Flower </label>
<input type="file" placeholder="flower" name="im">
<button type="submit">Upload</button>
</form>

models.py

class flower_tbl(models.Model):
fl=models.CharField(max_length=15)
pr=models.IntegerField()
im=models.FileField(upload_to="images")

admin.py
admin.site.register(flower_tbl)

#views.py

def image_upload(request):
if request.method=="POST":
flname=request.POST.get('fl')
price=request.POST.get('pr')
image=request.FILES.get('im')
obj=flower_tbl.objects.create(fl=flname,pr=price,im=image)
obj.save()
return render(request,"file.html")
def image_view(request):
obj=flower_tbl.objects.all()
return render(request,"file_view.html",{"data": obj} )

#urls.py

urlpatterns = [
path('', views.index),
path('reg', views.reg),
path('log',views.log),
path('work',views.work),
path('edit',views.edit),
path('update',views.update),
path('delete',views.delete),
path('image',views.image_upload),
path('file_view',views.image_view),

]+static (settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

#settings.py
MEDIA_URL='media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')

#file_view.html
{% load static %}
<body>
<form action="file_view" method="post">
{% csrf_token %}

{% for f in data %}

<!-- <div class="main" > -->

<!--cards -->

<div class="card">

<div class="image">

<img src="{{f.im.url}} " style= "width: 200px; height: 200px;" >


</div>
<div class="Dalia">
<h1>
{{f.fl}}</h1>
</div>
<div class="price">
<p>{{f.pr}} rs</p>
<button class="butt">View</button>
</div>
</div>
<!-- </div> -->
{% endfor %}
</form>
<style >
.card
{

float: left;
width: 25%; padding: 0 10px ;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
padding: 16px;
text-align: center;
}
.price{
font-size: 35px;
}
.butt{
background-color: rgb(176, 98, 249);
width: 50px;

}
</style>
</body>

You might also like