Hello friends !!
So my project requires me to store images on blob service of windows azure .I am using django in visual studio express . I even have an azure account..
So I wrote the code using a lot help from internet (I was total beginner to django when I started this project ) . My code works perfectly fine for django admin interface i.e. my images are getting stored on azure blobs online and using the stored URL(in my models field) I am able to access it also.
But the problem comes when I am creating my own form which will take image As input from user and upload it to my account's blob service !
The image is not getting stored !! I don't know what's wrong with my code !!
It was working well when I was working with django default filesystem .The same models.py works for admim interface but for my normal GUI it is not working !!
One more thing , I created my form as we do in normal HTML and I am not using django form class !!
Plzz help me !! I am totally stuck .
I am a newbie in django !!
######################################################### models.py ###################################################################################
.....
....
def get_upload_file_name(instance, filename):
return "assets/uploaded_files/%s_%s" % (str(time()).replace('.','_'), filename)
class Account(models.Model):
email =models.EmailField(max_length=254,primary_key= True)
password =models.CharField(max_length=20)
name =models.CharField(max_length=50)
dob_d=models.IntegerField(max_length=2)
dob_m=models.IntegerField(max_length=2)
dob_y=models.IntegerField(max_length=4)
class Accountinfo(models.Model):
email = models.ForeignKey(Account,primary_key=True)
pic=models.FileField(max_length=255, storage=AzureStorage(account_name="clique",account_key="xxx",container="new-public-container"),upload_to=get_upload_file_name)
about=models.CharField(max_length=254)
def get_thumbnail(self):
thumb = str(self.pic)
return thumb
#################################################################### views.py ################################################################
.....
.....
....
def uploadpic(request):
if request.method=="POST":
imail=request.POST.get('inputemail')
dbaccount=Account.objects.get(email=imail)
ifile=request.POST.get('inputfile')
print(type(ifile))
iabout=request.POST.get('inputabout')
account1=Accountinfo(email=dbaccount,pic=ifile,about=iabout)
account1.save()
print(ifile)
return render(request,'success.html',{"message":"congrats","name":imail})
################################################################### my template profile.html ################################################################
....
...
...
<form class="form-signin" action="{% url 'uploadpic' %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<h2 class="form-signin-heading">upload</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputemail" name="inputemail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputabout" class="sr-only">ABOUT YOURSELF</label>
<input type="text" id="inputabout" name="inputabout" class="form-control" placeholder="About" required autofocus />
<label for="inputfile" class="sr-only">Select</label>
<input type="file" id="inputfile" name="inputfile" class="form-control" placeholder="file" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">upload</button>
</form>
This thing is working via admin interface , but through my created form it is not!!!
Mt file is not getting stored !!!